I am currently using the following P/Invoke signature to get the short filename of a regular Windows file:
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName([MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
int shortPathLength);
Currently - it is working without any problems, but I noticed something rather peculiar:
I know that Windows uses the following short filename convention:
Cut the name to 6 characters (without extension)
Append the tilde (~
)
Append an unsigned integer number which indicates the match index (starting with 1)
Append the original file extension
Thus, the file name C:\abcdefghijklmn.txt
should be accessible under the short name C:\abcdefg~1.txt
. (Which is working perfectly fine.)
Now the strange part: I recently performed a small search inside my music directory for specific audio files. This was the result:
.\Rammstein & Tatu - Moscow.mp3
.\Rammstein - Asche zu Asche.mp3
.\Rammstein - Der Meister.mp3
.\Rammstein - Du Hast.mp3
.\Rammstein - Eifersucht.mp3
.\Rammstein - Feuer Frei.mp3
.\Rammstein - Führe Mich.mp3
.\Rammstein - Haifisch.mp3
...
And the same search in short notation:
.\RA8E17~1.MP3
.\RA23A6~1.MP3
.\RAMMST~1.MP3
.\RA0CAE~1.MP3
.\RAMMST~2.MP3
.\RAMMST~3.MP3
.\RAMMST~4.MP3
.\RA6BAA~1.MP3
...
My question is: Why is windows generating such "random" prefixes before the tilde (like RA23A6
or RA0CAE
)?
Microsoft does not document this, but Wikipedia does:
8.3 filename:
As Joey mentioned, the undocumented hash of the filename has been reverse engineered.