views:

37

answers:

2

I'm writing a program that searches directories of a computer. On my own computer I have a drive installed which previously booted Windows Vista.

(However, there are drives that do not appear even when "show hidden folders". I can see the folders running cmd, but that doesn't solve my problem.)

I don't care so much about the folders, but I do care about doing string comparisons with their names. However string.equals() and string.compareTo() does not work with these phantom folders when I get their name with File directory.getName().

I've printed out the names, checked for whitespace, used trim, etc. but a hidden folder named "Boot" will still not match with a string with same value.

TLDR: phantom directories return an unmatchable/comparable string with File directory.getName().

Besides solving the problem, I'm just curious to know what's going on.

+2  A: 

You may be getting hidden characters in the name. Check the string length of the Boot folder to see if it is four. Convert the String into an array of characters and examine each cell in a debugger.

harschware
A: 

Use Invariant comparisons when comparing filenames.

Paul Betts
Umm ... are you talking about C# "StringComparer.InvariantCulture"? If so, this concept is not relevant to "String.equals()" in Java.
Stephen C
This concept is relevant regardless of programming language, if he's talking about compareTo
Paul Betts