Strange behavior when displaying directory contents using


I'm using to do some windows directory searching. Basically the user inputs a directory path and I validate the path with file.isDirectory(). If the path is invalid I ask the user to re-enter a correct path. Once I get a valid directory I proceed with other File operations.

Now the problem occurs when the user enters the root directory. For example, e:. In this case file.list() provides the following output [.classpath, .project, .settings, bin, src].
As you can see this does not include any folders.

However if he enters e:\ then file.list() fetches the existing directories also [$RECYCLE.BIN, <some directories>, <some files>, RECYCLER, System Volume Information]

This time we don't have classpath, project etc. yet both e: and e:\ are considered valid directories.

1) Can someone explain this strange behavior?

2) Also, to avoid this problem is there a better method than adding a dirty manual check for x: and converting it into x:\?

First of all, .settings, bin and src ARE folders.
Secondly, do you actually have those files (.classpath, .project, etc.) in drive e: ?

My guess is, java doesn't parse "e:" correctly, and file.list() gives you the list of files under the jvm current folder, which happens to be the folder where your eclipse project files reside (All those files AND folders that you mentioned belong to an eclipse project).

Try opening a command-line window. On my machine it opens at c:\Windows\System32. Then type "cd c:" and see what happens ...