Skip to main content

How to get list of directories only using FileConnection?

5 replies [Last post]
arnab321
Offline
Joined: 2008-11-16
Points: 0

im sure u have seen jme applications listing only the directories. does it have anything to do with the list(String,boolean) method of FileConnection? if yes, how to use it to list only directories?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
davjoh
Offline
Joined: 2007-07-18
Points: 0

Another way could be to open a FileConnection to each item in the enumeration returned by list(), and use isDirectory() on the opened FileConnection.

jaywayjohan
Offline
Joined: 2008-06-18
Points: 0

davjoh:

Your solution is a little bit cleaner in code. The big disadvantage is that opening and closing FileConnection could take some time on some platforms.

Regards
Johan

jaywayjohan
Offline
Joined: 2008-06-18
Points: 0

Hi,

you are using the correct method, but the method has no support for filtering on directories. Thus you have to figure out for yourself which is a directory and which is a file.

Best Regards
Johan

arnab321
Offline
Joined: 2008-11-16
Points: 0

well, i found out. i donno whether it is legal or not, but i was curious about how opera mini splayed only the names of directories when downloading a file. so i got JAD, and decompiled the jar, and after a long hunt, realised that its a very simple technique. Directory names end with "/". fo, u can just scan through the Enumeration returned by .list(), for those names which end with "/"

jaywayjohan
Offline
Joined: 2008-06-18
Points: 0

Yes, using "/" to figure out which is a directory or not should be the best bet. Nice to hear that you figured it out :)

Regards
Johan