Reputation: 43
I have a PC running 64 bit Windows Server 2003. There is a java application which uses cmd file as a launcher. The launcher does this
SET JAVA_HOME= C:\Progra~1\Java
"%JAVA_HOME%\bin\java" [java program execution line]
Java is installed in C:\Program Files\Java. Since it is a x64 windows it also has C:\Program Files (x86)\ folder.
Now the actual problem is that from time to time this application fails to start because it fails to find java.
So the question is what windows does to resolve such ambiguity? Based on what it makes decisions about which folder to choose?
Upvotes: 4
Views: 9541
Reputation: 745
The association between long and short names is made when the directory is created. Windows creates a "short path entry" in the directory that contains the 8.3 name. So the association between the short and long name is permanent and doesn't change unless you modify the directories ( rename, delete, recreate ).
This is an example on my machine ( windows 7 )
C:\>mkdir temp
C:\>cd temp
C:\temp>dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0A74-FE30
Directorio de C:\temp
24/05/2010 12:14 p.m. <DIR> .
24/05/2010 12:14 p.m. <DIR> ..
0 archivos 0 bytes
2 dirs 6.090.723.328 bytes libres
C:\temp>mkdir "Program Files"
C:\temp>mkdir "Program Files (x86)"
C:\temp>mkdir "Program Files (x86_64)"
C:\temp>dir /x
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0A74-FE30
Directorio de C:\temp
24/05/2010 12:15 p.m. <DIR> .
24/05/2010 12:15 p.m. <DIR> ..
24/05/2010 12:14 p.m. <DIR> PROGRA~1 Program Files
24/05/2010 12:14 p.m. <DIR> PROGRA~2 Program Files (x86)
24/05/2010 12:15 p.m. <DIR> PROGRA~3 Program Files (x86_64)
0 archivos 0 bytes
5 dirs 6.090.723.328 bytes libres
C:\temp>rmdir "Program Files"
C:\temp>mkdir "Program Files (new)"
C:\temp>dir /x
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0A74-FE30
Directorio de C:\temp
24/05/2010 12:15 p.m. <DIR> .
24/05/2010 12:15 p.m. <DIR> ..
24/05/2010 12:15 p.m. <DIR> PROGRA~1 Program Files (new)
24/05/2010 12:14 p.m. <DIR> PROGRA~2 Program Files (x86)
24/05/2010 12:15 p.m. <DIR> PROGRA~3 Program Files (x86_64)
0 archivos 0 bytes
5 dirs 6.090.723.328 bytes libres
C:\temp>rmdir "Program Files (x86)"
C:\temp>dir /x
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0A74-FE30
Directorio de C:\temp
24/05/2010 12:15 p.m. <DIR> .
24/05/2010 12:15 p.m. <DIR> ..
24/05/2010 12:15 p.m. <DIR> PROGRA~1 Program Files (new)
24/05/2010 12:15 p.m. <DIR> PROGRA~3 Program Files (x86_64)
0 archivos 0 bytes
4 dirs 6.090.723.328 bytes libres
As you can see, the name PROGRA~1 is "reused" when I delete the original directory, and create a new one with a name that, when shortened, matches the "PROGRA" prefix.
hth
Upvotes: 1
Reputation: 88796
The simple answer is that Windows stores both short and long filenames.
It did this back when vfat (on top of FAT16) was introduced with Windows 95, continued in FAT32, and is still around in NTFS:
When you save a file with a long file name to an NTFS drive, NTFS creates, by default, a second file directory entry with a short file name conforming to the 8.3 convention.
(You can disable 8.3 names on NTFS).
Side Note: You can see what the short filenames are in a cmd.exe window by running dir /x
(thank to cHao for pointing this out).
Upvotes: 2
Reputation: 86505
Whenever a file is created on an NTFS filesystem, the OS can (and pre Windows 7/2008, usually does) also create a short name for it. It's not required, and the name can actually be anything, but if the regular name isn't already 8.3, the short name is usually the first 6 word-characters of the filename, a tilde (~), and a digit (1 for the first file with those same first chars, 2 for the second, etc), a dot, and the first 3 letters of the extension. (If there's no extension, there's usually no dot either.)
The number doesn't relate otherwise to the name of the file, meaning "program files" can become "progra~1" or "progra~2" or "progr~50", depending on what other files/dirs in that same location are called and (mostly) when they were made. But once the name's set, it rarely changes unless the file is renamed.
Upvotes: 0
Reputation: 718816
The gory (patent infested) details are also described in this Wikipedia page.
Upvotes: 0