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 need to find and delete all files in subdirectories that are not .SQL files. I can't figure out how to search for <>.SQL or !.SQL in Windows Search.

Most of the solutions that I've seen here are to find specific extensions and do something with them. I'm looking for the opposite.

share|improve this question

migrated from stackoverflow.com Jul 6 '11 at 1:27

This question came from our site for professional and enthusiast programmers.

yeah it's very easy to search for a specific file, but how do you search for everything that's not a specific file. –  Nico Jul 5 '11 at 14:53
i can't search for <>*.sql or !*.sql in windows search ? –  Nico Jul 5 '11 at 14:53
I do not believe this is a function of the Windows default search. You would most likely need to write a script or install a tool like grep. –  Mike Soule Jul 6 '11 at 0:24

2 Answers 2

up vote 6 down vote accepted

I don't know of a way to do it from Windows Search, but from the command line it is:

dir /s /b /a-d | findstr /v /r ".*\.sql"
  • dir /s - recursive directory listing
  • /b - bare listing, only file names (no directory size info etc. in the output)
  • /a-d - filter by attributes, not directory (remove sub directories from the listing)
  • | (pipe) - send the output of the directory listing to
  • findstr - text search utility
  • /v - only return lines that don't match
  • /r - use regular expressions
  • ".*.sql" - match anything any number of times followed by a dot followed by sql
share|improve this answer
You don't need regular expressions for this. After the pipe, findstr /v "*.sql" should work just fine. Thanks, though! –  Iain Elder May 4 '12 at 23:29
If you want to do something with the output of this command (e.g. delete the files), you can use this inside a batch file: FOR /f "tokens=* USEBACKQ" %%a in (`dir /s /b /a-d ^| findstr /v /r ".*\.sql"`) DO del /f /q "%%a" –  WackGet Aug 17 '13 at 3:31

If you insist on using Windows search which doesn't have a native ability or support for such a feature, you could simply run it this way:

*.a OR *.b OR *.c OR *.d OR *.e OR *.f OR *.g OR *.h OR *.i OR *.j OR *.k OR *.l OR *.m OR *.n OR *.o OR *.p OR *.q OR *.r OR *.t OR *.u OR *.v OR *.w OR *.x OR *.y OR *.z

Following search will exclude all files with .s* extensions, while listing all others.

Perhaps there is a better way to do it, but this should work as well.

share|improve this answer
File extensions usually have 3 characters not 1. 26^3 = 17576 different combinations.......... –  Pacerier Aug 27 at 13:24

Your Answer


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.