Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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
I know this is way old, but this question… has a brilliant answer. In Explorer search for "NOT *.sql" (capitalization of NOT matters) . It was new to me but I tested it and it works. You can even do "NOT *.mp3 NOT *.aiff NOT *.m4p". Even further you can go "NOT folder" to exclude folders from the results. – Jeff Jul 17 '15 at 20:06
up vote 7 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
This is good, and what I came up with as well. It'd be nice to find a way to do this without using dir \b (so I could see date, size, etc) and without using a for /f loop. – user1167442 Mar 13 at 22:57

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 '14 at 13:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .