Reputation: 1579
(background)
I'm using Java.io.File
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.
(problem)
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:\
?
Upvotes: 1
Views: 1483
Reputation: 1284
e: will list the CURRENT directory in the e: drive
e:\ will list the ROOT directory in the e: drive
Try this:
cd c:\windows\system32
dir c:
dir c:.
dir c:\
"c:" is the same as "c:."
Upvotes: 3
Reputation: 10321
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 ...
Upvotes: 2
Reputation: 108909
I expect something is interpreting "e:"
as the current directory of the volume e: (which may not be the root). Raymond Chen recently covered the history of this sort of thing.
Upvotes: 3