Take the 2-minute tour ×

In MS-DOS, if I enter dir *.pdf, I'll get all the PDF files in a directory. Is there a way to get everything but PDF files? Something like dir !*.pdf?


share|improve this question

5 Answers 5

up vote 11 down vote accepted

I think there's a /v option for findstr which is equivalent to grep -v (include all lines that don't contain the text. So I'd be looking at:

dir | findstr /vi ".pdf"

The syntax may be slightly different, I haven't had much need to use it and I don'r run Windows at my current location.

Use findstr /? from a command prompt for details.

Or, if you install CygWin (my tool of choice for this sort of stuff), you can just use grep itself:

ls -al | grep -vi '\.pdf$'


I actually didn't realize this but apparently findstr also support regexes so you can use:

dir | findstr /vi "\.pdf$"

just the same as grep (I haven't tested this, I only just found it on TechNet, so you'll need to test it yourself).

share|improve this answer
+1 That seems to do it - nice work. –  Andrew Hare May 7 '09 at 14:40
Thanks, @Andrew, I didn't really want to crank up VMWare Player just to test it :-) –  paxdiablo May 7 '09 at 14:41
Works great. Thanks! –  IVR Avenger May 7 '09 at 14:44

You can combine dir with findstr to almost do what you want:

dir * | findstr /vi .pdf

Note though, that if a file is called my.pdf.converted.txt, it will be incorrectly thrown away here.

If you REALLY want to get fancy, here's a completely correct version, more appropriate for a batch script:

for /f %a in ('dir /b *') do @if "%~xa" neq ".txt" echo %a

Good luck no matter what you try :) DOS is "fun".

share|improve this answer
Blessedly, I'm not dealing with any tricks like your "pdf.converted.txt" example. Good catch, though! –  IVR Avenger May 7 '09 at 14:44
findstr in XP tells me it can handle regex well enough to match the end of the line in the usual way, too –  Anonymous May 7 '09 at 14:44

I know it's working for you already but you could do it with most versions of DOS (at least the ones I can remember) like this.

Attrib *.bad +H
dir /oE
Attrib *.bad -H

Which has the affect of hiding the ones you don't want to display, doing the dir then unhiding them. Its a bit nasty I must admit but it does seem to do the trick.

share|improve this answer

In MS-DOS or CMD you just type for avoiding pdf files:

dir | find/V ".pdf"

But remember the count of files at the bottom of the output will include the pdf file(s).

Besides you can also use this command for other extensions as well by replacing ".pdf" to ".xxx", where xxx is any extension.

share|improve this answer

Here's one simple way without using findstr/find or piping to another command:

for %%a in (*) do (
    if not exist %%~Na.pdf   echo %%a

Basically the for loop will loop through all the files. The "if not exist" will ensure no *.pdf file is printed

The %%~Na means use the filename of %%a variable without its extension.

share|improve this answer

Your Answer


