Excluding files of particular extension using DIR command on windows command line

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$" 

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 :)


It depends on 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. However, the tool from JP Software's TCC/LE has this feature. It is called a file exclusion range and is used like this for the example in your question:

dir /[!*.exe] *