I\'m trying to make a batch file on Windows for deleting all the files in the current directory but excluding 4 file extensions (log, sdb, SDK, bat).
I have tried th
I ran across this topic searching for a way to delete hundres of files created by a virus. Non of the solutions really worked for me, so I figured out how to do it from a command line. I needed only to keep 2 extensions (mail archive). This did the trick:
for /R %f in (*) do if not %~xf==.ex1 if not %~xf==*.ex2 del "%f"
I use the /R to work recursive: look in all subfolders. The %~xf looks at the extension only (for some reason it didn't work without it). I use the quotes "%f" at the delete command to cover the windows long names with spaces (especially in folder names). Also for some reason, adding spaces before and behing the == gave errors.