Phantom folders from hell (old Vista installation) causing Java String.equals () problems

I am writing a program that searches for directories on a computer. On my own computer, I have a disk that was previously loaded in Windows Vista.

(However, there are disks that don’t appear even when “show hidden folders.” I see folders working with cmd, but this does not solve my problem.)

I don't care about folders, but I really care about comparing strings with their names. However, string.equals () and string.compareTo () do not work with these phantom folders when I get their name using File directory.getName ().

I printed the names, checked for spaces, used cropping, etc., but the hidden folder with the name "Download" still does not match the line with the same value.

The TL; DR: phantom lists return an immutable / comparable string to the directory.getName () file.

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

+3
source share
2 answers

You can get hidden characters in the name. Check the length of the line in the Boot folder to see if it equals four. Convert String to an array of characters and check each cell in the debugger.

+2
source

Use invariant comparisons when comparing file names.

0
source

Source: https://habr.com/ru/post/1751486/


All Articles