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 recursively search a directory tree to find all of the .asp files using the following command:

dir *.asp /s

For some reason, this returns not only the asp files, but also the aspx files.

How can I force it to ignore the aspx files?

share|improve this question
add comment

4 Answers

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.

The "extension" part of a 8.3 name is always created by simply truncating the last extension to at most 3 characters: .aspx to .ASP


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. You will have to rename each file and then rename it back to its original name.


See also: Directory search in Windows Command Prompt shows incorrect output!

share|improve this answer
    
Well, that's a pretty good explanation of why - but it seems like there isn't a way to then force the dir command to ignore the aspx files? –  chris Jan 28 '11 at 14:17
1  
@chris: No. But you can either remove the 8.3 names from your system (will likely save you a lot of trouble later), or filter the dir output with dir /b/s *.asp | findstr /ile .asp -- this discards lines that do not end with .asp. –  grawity Jan 28 '11 at 14:19
add comment

Of course this varies according to what command interpreter's DIR command one uses. The DIR command in Take Command, for example, only matches long names by default and so doesn't exhibit this behaviour. (Matching of short as well as long names can be turned on for compatibility with CMD's DIR command.) So there are ways to address this that don't require FSUTIL and administrator privileges.

share|improve this answer
add comment

Interesting - seems to be a bug...

Considering, I would pipe it through find like so:

dir /s *.asp | find /i /v ".aspx "
share|improve this answer
add comment

If you have PowerShell, you can use:

dir *.asp -r | remove-item

If you don't have PowerShell, why not?

share|improve this answer
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.