Hi,
I have a function to list the contents of a directory. For the
contents of the directory "/System", both isDirectoy and isFile
functions return a false value. How is this possible? Please clarify.
The code snippet for reference:
1. public void populateContents(String dir) {
2. Log.v(TAG, "in populateContents, dir: " + dir);
3. File file = new File(dir);
4. if (file.isDirectory()) {
5. try {
6. Log.v(TAG, "in populateContents, mCurDir: "
7. + mCurDir.getCanonicalPath());
8. } catch (IOException e) {
9. // TODO Auto-generated catch block
10. e.printStackTrace();
11. }
12. String[] fileList = file.list();
13. for (int ix = 0; ix < fileList.length; ix++) {
14. Log.v(TAG, "in populateContents, fileList[" + ix
+ "]: "
15. + fileList[ix]);
16. File nFile = new File(fileList[ix]);
17. String str = "";
18. if (nFile.isDirectory()) {
19. Log.v(TAG, "in populateContents, fileList["
+ ix + "]: "
20. + fileList[ix] + " is a
directory");
21. str = "[D->]";
22. String[] insideDir = nFile.list();
23. if (insideDir.length > 0) {
24. Log.v(TAG, "in populateContents, fileList
[" + ix
25. + "]: " + fileList[ix] + " is a
directory"
26. + " and is non-empty");
27. str = "[D->(...)]";
28. }
29. } else if (nFile.isFile()) {
30. Log.v(TAG, "in populateContents, fileList["
+ ix + "]: "
31. + fileList[ix] + " is a file");
32. } else {
33. Log.v(TAG, "in populateContents, fileList["
+ ix + "]: "
34. + fileList[ix]
35. + " is neither a file nor a
directory");
36. }
37. }
38. }
39. }
I am getting logs in logcat like this:
V/->->FEX ( 350): in populateContents, fileList[0]: bin
V/->->FEX ( 350): in populateContents, fileList[0]: bin is neither a
file nor a directory
V/->->FEX ( 350): in populateContents, fileList[1]: build.prop
V/->->FEX ( 350): in populateContents, fileList[1]: build.prop is
neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[2]: etc
V/->->FEX ( 350): in populateContents, fileList[2]: etc is a directory
V/->->FEX ( 350): in populateContents, fileList[2]: etc is a directory
and is non-empty
V/->->FEX ( 350): in populateContents, fileList[3]: app
V/->->FEX ( 350): in populateContents, fileList[3]: app is neither a
file nor a directory
V/->->FEX ( 350): in populateContents, fileList[4]: usr
V/->->FEX ( 350): in populateContents, fileList[4]: usr is neither a
file nor a directory
V/->->FEX ( 350): in populateContents, fileList[5]: fonts
V/->->FEX ( 350): in populateContents, fileList[5]: fonts is neither a
file nor a directory
V/->->FEX ( 350): in populateContents, fileList[6]: media
V/->->FEX ( 350): in populateContents, fileList[6]: media is neither a
file nor a directory
V/->->FEX ( 350): in populateContents, fileList[7]: sounds
V/->->FEX ( 350): in populateContents, fileList[7]: sounds is neither
a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[8]: lib
V/->->FEX ( 350): in populateContents, fileList[8]: lib is neither a
file nor a directory
V/->->FEX ( 350): in populateContents, fileList[9]: xbin
V/->->FEX ( 350): in populateContents, fileList[9]: xbin is neither a
file nor a directory
V/->->FEX ( 350): in populateContents, fileList[10]: framework
V/->->FEX ( 350): in populateContents, fileList[10]: framework is
neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[11]: lost+found
V/->->FEX ( 350): in populateContents, fileList[11]: lost+found is
neither a file nor a directory
Regards,
Anirudh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---