Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT
Accepted Solution

How could I get all filename in a directory?

Purpose:

Try to get all filename in a directory.

 

My code:

FileConnection fconn = (FileConnection) Connector.open(fileDirectory);
//Enumeration files = fconn.list();
Enumeration files=fconn.list("*",true); //try
_screen.updateDisplay(files); //shows unreadable txt.
String filename = fconn.getName();
_screen.updateDisplay1(filename); //show WMMS/

 

Try to use fileconnection.getName(). --> But fail.

 

Could anyone give a hint to fix the issue?

 

Thanks your attention,

 

 

 

 

-Fight with BB10
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How could I get all filename in a directory?

work with the enumeration.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: How could I get all filename in a directory?

Hi Simon,

 

Try to print.out or write to show filename on a list or log, but fail.

Could u help me more to solve the issue?

 

Enumeration files=fconn.list("*",true);//the same result as above line.
System.out.println(files);
logfile1.writeStringToLog(files);

 

 

Thank you a lot,

 

 

-Fight with BB10
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How could I get all filename in a directory?

you cannot just print out an Enumeration.
It is a collection that contains objects, in this case Strings, as you can see on http://www.blackberry.com/developers/docs/7.1.0api/javax/microedition/io/file/FileConnection.html#li...

you can use a while construct to iterate through the enum, like:
while (files.hasMoreElements()){
System.out.println(files.nextElement());
}
(don't know if you need an explicit cast to string for sysout, iirc not)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: How could I get all filename in a directory?

Solve it, Thx Simon a lot.

 

Final solution. Just share it.

 

FileConnection fconn = (FileConnection) Connector.open(fileDirectory,Connector.READ_WRITE);
if (!fconn.exists())
{
fconn.create();// create the file if it doesn't exist
}
Enumeration files=fconn.list("*",true);
while (files.hasMoreElements()){
_screen.updateDisplay(files.nextElement());
}

-Fight with BB10