I searched for the following and it gave me the exact output (folder names changed)

C:\temp>dir *950*.pdf /s
 Volume in drive C has no label.
 Volume Serial Number is ABCDE

 Directory of C:\temp\e\h\d\20100809

08/08/2010  10:54 PM         1,632,434 09_08_2010_004.pdf
08/08/2010  10:54 PM         1,368,895 09_08_2010_003.pdf
08/08/2010  10:54 PM         2,111,360 09_08_2010_005.pdf
               3 File(s)      5,112,689 bytes

I dont understand why "950" is being matched against these 3 files...!

Edit1

I actually moved it into c:\temp\ this time and it matches one of them!

 C:\temp\20100809>dir *950*.pdf
 Volume in drive C has no label.
 Volume Serial Number is ABCDE

 Directory of C:\temp\20100809

08/08/2010  10:54 PM         2,111,360 09_08_2010_005.pdf

Edit2

@gravvity's answer is on the dot!

C:\temp\20100809>dir *950*.pdf /x
 Volume in drive C has no label.
 Volume Serial Number is ABCDE

 Directory of C:\temp\20100809

08/08/2010  10:54 PM         2,111,360 09507E~1.PDF 09_08_2010_005.pdf
link|improve this question

71% accept rate
Can you reproduce this in another directory structure? – Dennis Williamson Jan 20 '11 at 6:17
@Dennis - please see Edit1 – matt74tm Jan 20 '11 at 7:15
feedback

1 Answer

up vote 6 down vote accepted
dir /x

For compatibility reasons, Windows generates a 8.3 name for every long file name created, and wildcard matching code (FindFirstFile()) checks both the original and shortened names. Use dir /x to see what short names are assigned to each file.

Usually the auto-generated short names look like 090820~1.PDF and 090820~2.PDF and so on, but there are exceptions:

[...] if at least 4 files or folders already exist with the same initial 6 characters in their short names, the stripped LFN is instead truncated to the first 2 letters of the basename (or 1 if the basename has only 1 letter), followed by 4 hexadecimal digits derived from an undocumented hash of the filename, followed [...]

Moving a file within the same partition does not change either of its names, only relocates them.


When using the NTFS filesystem, 8.3 name creation can be disabled system-wide using:

fsutil behavior set disable8dot3

However, this won't affect existing names.

link|improve this answer
1  
+1 Brilliant answer! (perhaps not so brilliant implementation) – Dennis Williamson Jan 20 '11 at 15:10
1  
+1 Brilliant answer! – matt74tm Jan 20 '11 at 20:50
feedback

Your Answer

 
or
required, but never shown

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