Windows still uses ~ for shortening files and directories with long names. You can see the "short" name by typing dir /X in the command prompt.

My question is how are the digits assigned to the short file names? It doesn't seem to be alphabetical nor does it seem to work by file creation time.

For example:

I create a new text file: C:\reallylongfilenameB.txt

Then I run dir /X and see the short name of fileB is REALLY~1.TXT

I create a second text file: C:\reallylongfilenameA.txt

Then I run dir /X and see the short name of fileA is REALLY~2.TXT

Then I set the clock back a day, delete C:\reallylongfilenameA.txt and then re-create it, essentially making the create date of C:\reallylongfilenameA.txt 1 day before C:\reallylongfilenameB.txt.

I run dir /X and C:\reallylongfilenameA.txt short name is still REALLY~2.TXT.

Given this example, is there any way to make the short name of C:\reallylongfilenameA.txt be REALLY~1.TXT?


As I understand it, NTFS automatically assigns persistent 8.3 filenames upon creation. When you run dir /X, it's not shortening filenames on-the-fly, it's looking up the preassigned short names.

Source: http://en.wikipedia.org/wiki/8.3_filename

  • Hmm interesting. So to answer in terms of my example, if I move both files to C:\temp then move reallylongfilenameA.txt back to C:\ before reallylongfilenameB.txt; then fileA will be REALLY~1.TXT and fileB will be REALLY~2.TXT – FGreg Dec 5 '13 at 16:56
  • No, I don't think so. It's possible for there to be a REALLY~2.TXT in a directory without a corresponding REALLY~1.TXT, if you take the first one out. – Jack Dec 12 '13 at 17:43
  • Yes that is true. I was making a different point that I could change which file was '1' and which file was '2' by moving them both out of the directory then moving the file that was '2' back into the directory (therefore making it '1'). Btw, tried this and it works on Win 7. – FGreg Dec 12 '13 at 17:56

As Jack pointed out in his answer, the short name is assigned when the file is created (or renamed, or moved). The value is dependent both on the long file name, as well as what other short names already exist.

The exact short name assignment algorithm is undocumented, and there is no guarantee that the algorithm remains constant between Windows versions, or even between different storage system formats. You should not write code that is dependent on any particular short name assignment algorithm.

There are both design limitations and bugs that arise from short file names. An example of a design limitation is del *.txt can delete a file named something.txt2 because the extension of the short name will probably be .txt, and source masks look at both long and short names. See the section titled "BUG - Short 8.3 filenames can break the /D and /S options " at What are the undocumented features and limitations of the Windows FINDSTR command? for an example of a bug arising from short names.

NTFS volumes can have short file names disabled (short names that existed prior to disabling them will remain). Many people (organizations) disable short names on their system because of the problems they can cause.


Here is a definitive argument for why it is a waste of time trying to establish the algorithm for how short file names are generated - FSUTIL allows you to specify any short name you want for a file, as long as it does not already exist in that folder.

Here is the relevant FSUTIL help documentation

C:\test>fsutil file
---- FILE Commands Supported ----

findbysid               Find a file by security identifier
queryallocranges        Query the allocated ranges for a file
setshortname            Set the short name for a file
setvaliddata            Set the valid data length for a file
setzerodata             Set the zero data for a file
createnew               Creates a new file of a specified size
queryfileid             Queries the file ID of the specified file
queryfilenamebyid       Displays a random link name for the file ID

C:\test>fsutil file setshortname /?
Usage : fsutil file setshortname <filename> <shortname>
   Eg : fsutil file setshortname C:\testfile.txt testfile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.