Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOS: Directory listing that excludes a file type?

Tags:

dos

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?

Thanks!

like image 840
IVR Avenger Avatar asked May 07 '09 14:05

IVR Avenger


2 Answers

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

Addendum:

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

like image 56
paxdiablo Avatar answered Jan 04 '23 05:01

paxdiablo


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

like image 31
Mike Avatar answered Jan 04 '23 04:01

Mike