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.

if i want to see e.g. files of a particular extension only using dir listing, i can do that using the command:

DIR *.txt 

And it shows all files with .txt extension.
Now i want to know is there any command with wich i can exclude certain extensions?
For example, i don't want to see any file with extension .exe, how can i do that?

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

DIR wont allow what you are trying to do. However DIR along with FINDSTR can solve this.

e.g. The following ignores all .txt files in the DIR listing.

dir | findstr /v /i "\.txt$" 
share|improve this answer
    
thanks a lot, very useful –  Johnydep Jan 29 '12 at 14:28
add comment

It depends from your command interpreter.

Microsoft's cmd doesn't have such a facility, as you can see from the other answers where one has to post-process the output of dir. JP Software's TCC/LE does. It is called a file exclusion range and is used like this for the example in your question:

dir /[!*.exe] *

share|improve this answer
    
Thank you, but i think this tool run as standalone program. I am making my application where i run external process using windows shell or bash in ubuntu, so this tool will not fit, If they provide cmd line switches then it will be useful. –  Johnydep Jan 30 '12 at 0:01
1  
The aforegiven clearly is a command-line switch. Read the hyperlinked documentation. Of course, in most programming languages it is fairly silly to go to the length of using the shell for obtaining directory contents, and you are on the wrong StackExchange for writing applications. –  JdeBP Jan 30 '12 at 8:09
    
thanks for the explanation, that's true but it is a workaround for scanning those directories which require Elevation and i don't want to make my code trigger UAC prompt, when i can get results from cmd prompt without requiring higher privilege. –  Johnydep Jan 31 '12 at 16:21
add comment
dir /B | find /V ".txt"

This would list all files and find would filter out anything that doesn't contain ".txt". It's far from perfect, but maybe it's enough :)

share|improve this answer
    
thanks a lot, produces well formatted results –  Johnydep Jan 29 '12 at 14:29
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.