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

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: 16,987
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: 16,987
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