One little problem with Windows is that nothing is case sensitive. As a result, people don't realize that case matters and it is often a source of screw-up on other operating systems. So I wrote this code which checks if a file exists; if it doesn't, it gets a directory listing and checks if each file matches in a case-insensitive way. Not the fastest way to do it, but I can't think of a better way.
Quote /** Attempts to find a file in a case-insensitive way. I suggest avoiding over-using this. Saving the
* new filename somewhere and re-using it is probably the best way to use this function.
*
* @param filename The full path to the file.
* @return The best guess at the case-insensitive filename. It will return the original filename if it
* is unable to find anything better. If there are multiple files with the same name and different
* cases, there is no guarentee as to which one is returned.
*/
private static String findFile(String filename)
{
File file = new File(filename);
File directory;
String []files;
if(file.exists())
return filename;
/* Get the directory listing */
directory = file.getParentFile();
files = directory.list();
for(int i = 0; i < files.length; i++)
{
if(files.equalsIgnoreCase(file.getName()))
return directory.getAbsolutePath() + "/" + files;
}
/* If it couldn't find it, just return the name we were given */
return filename;
}
And here's an example of using it:
Quote
public static void main(String []args)
{
System.out.println(findFile("/home/iago/.hashes/STAR/STarCrAFT.eXe"));
}
Which outputs exactly what you'd expect:
Quote/home/iago/.hashes/STAR/starcraft.exe
Quote from: iago on January 26, 2006, 08:58:53 PM
One little problem with Windows is that nothing is case sensitive.
Uh uh, that's not true. Case sensitivity is supported by NTFS and as well as the POSIX subsystem of Windows.
Quote from: MyndFyrex86] link=topic=4665.msg52424#msg52424 date=1138328001]
Quote from: iago on January 26, 2006, 08:58:53 PM
One little problem with Windows is that nothing is case sensitive.
Uh uh, that's not true. Case sensitivity is supported by NTFS and as well as the POSIX subsystem of Windows.
I've never seen case-sensitive Windows files. Is there some secret to enabling them?
I've never officially checked if it was possible, but by default it doesn't happen, so that's the important part.
The problem is, in bots, some people package the hash files with different cases than what I expect, because on Windows, by default, it doesn't matter.
Supported != Matterful
It's true that NTFS supports case-sensitivity, but Windows overlooks that fact because it realizes that 97% of it's users would be too stupid to realize that somefile isn't the same as SOMEFILE, and start deleting "duplicates".
Yeah, pretty much what R.a.B.B.i.T said.
Also, that's not *exactly* true, I've had the command prompt window bitch at me for not having "Documents and Settings" capitalized like that, for some reason.
Quote from: deadly7 on January 27, 2006, 07:06:12 PM
Yeah, pretty much what R.a.B.B.i.T said.
Also, that's not *exactly* true, I've had the command prompt window bitch at me for not having "Documents and Settings" capitalized like that, for some reason.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\>cd docuMENTS and SeTTinGS
C:\Documents and Settings>cd ../DOCUMENTS AND SETTINGS
C:\Documents and Settings>
I suspect you were using a command that had more than one parameter, like copy:
C:\>echo "" > "Documents and Settings\test.txt"
C:\>dir Documents
Volume in drive C has no label.
Volume Serial Number is D424-0774
Directory of C:\
01/27/2006 07:31 PM 28 Documents
1 File(s) 28 bytes
0 Dir(s) 12,835,221,504 bytes free
C:\>echo "" > "Documents and Settings\test.txt"
C:\>dir Documents and Settings\test.txt
The system cannot find the file specified.
C:\>dir "Documents and Settings\test.txt"
Volume in drive C has no label.
Volume Serial Number is D424-0774
Directory of C:\Documents and Settings
01/27/2006 07:32 PM 5 test.txt
1 File(s) 5 bytes
0 Dir(s) 12,835,221,504 bytes free
As you can see, unless you enclose a directory that contains spaces in quotes, it is truncated after the first space. I highly suspect that's the reason you were having issues with 'casing.'
By default, NTFS is totally non-case sensitive. It was weird seeing files with the same file and different casing when I first set up samba on my server.
That was probably it, Sidoh.. Command prompt blows anyways. :\