Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to do a directory listing of files with filenames consisting of 8 characters followed by a period and a file extension in Windows command shell. The wildcard pattern I'm using is "????????.TIF". This returns ALL filenames with the ".TIF" extension, regardless of the length of the pre-extension portion of the filename. Example:

dir A*.TIF

Returns ABCDEFGH.TIF and ABCDEFGHIJ.TIF

dir ????????.TIF

Also returns both files. I would expect only the first one would be returned, since it is the only one of the two that matches the pattern (8 single characters followed by ".TIF".) What is the explanation for this behavior?

Thanks in advance for any replies.

share|improve this question
add comment

3 Answers 3

up vote 7 down vote accepted

I think the problem is that ABCDEFGHIJ.TIF has a short name of something like ABCDEF~1.TIF and that is being matched by your pattern.

If you use DIR /X you will see the short names - ie. the 8.3 file name - of all your files.

You could try something like this:

DIR /B | FINDSTR /R /I "^........\.TIF"

This uses FINDSTR in regular expression mode to ensure exactly 8 characters before the .TIF. For more help on FINDSTR enter FINDSTR /? at a command line.

share|improve this answer
    
Thanks for the reply. Using "DIR /X" does display a short filename in it's output in addition to the longer name. Is there any way to filter out the short filenames with the DIR command? I don't see anything promising in the options with "DIR /?". –  E Brown Sep 14 '10 at 15:46
    
I don't know of a way to force DIR to only match long names which is why I suggested using FINDSTR to filter the output of DIR instead. –  Dave Webb Sep 14 '10 at 16:02
    
Thanks. I was going to install GNU Unix Utils and do a similar filtering with "grep". Wasn't aware of the "findstr" command, but your method worked fine for what I needed done. –  E Brown Sep 14 '10 at 18:41
add comment

If you want to correct this, open an elevated command prompt and type:

fsutil 8dot3name set 1

Existing files will still exhibit the problem until you have stripped off the short filename. New files that you copy/create will not have the issue. If you need to mass strip short filenames, you can use:

fsutil 8dot3name strip /s <directory>

The problem appears to stem from Windows 7 using the short filename for wildcards instead of the long filename.

share|improve this answer
add comment

? means match any single character. By doing a dir ????????.TIF you are saying return any files which have 8 characters and a .tif extension, while dir A*.tif means return any files which start with A or 'a' and have .tif as an extension

share|improve this answer
    
Thanks for the reply. I know that - I included the "dir A*.TIF" just to show the two files for illustration purposes. My need is to list only files with 8 characters and a .tif extension. The ????????.TIF pattern returns both the 8-character-and-a-.TIF filename and the 10-character-and-a-.TIF filename. I would expect it to return only the former, since the pattern specifies 8 single characters and a .tif extension. –  E Brown Sep 14 '10 at 15:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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