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.

link|improve this question
No code, no cookie – leppie Jul 5 '11 at 9:31
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
@leppie, this is not a code problem.. i probably should've put it on superuser, but i'm here now so .. I could probably write some sort of batch file using find, but i wanted to know if anyone has better ideas. – Nico Jul 5 '11 at 14:54
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
feedback

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

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

1 Answer

up vote 4 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
link|improve this answer
You don't need regular expressions for this. After the pipe, findstr /v "*.sql" should work just fine. Thanks, though! – isme May 4 at 23:29
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.