Directory search in Windows Command Prompt shows incorrect output

2

2

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

siliconpi

Posted 2011-01-20T05:21:37.790

Reputation: 2 067

Can you reproduce this in another directory structure? – Paused until further notice. – 2011-01-20T06:17:59.843

@Dennis - please see Edit1 – siliconpi – 2011-01-20T07:15:23.507

Answers

8

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.

user1686

Posted 2011-01-20T05:21:37.790

Reputation: 283 655

1+1 Brilliant answer! (perhaps not so brilliant implementation) – Paused until further notice. – 2011-01-20T15:10:31.640

0

I have that problem, and was tempted to use fsutil to disable short names systemwide, but decided against it. Instead I found out you can use fsutil.exe to associate the file with a better short name, as in:

fsutil.exe file setshortname 175002886.pdf ~1752886.pdf

You will need to do this as an administrator.

user48918

Posted 2011-01-20T05:21:37.790

Reputation: 141