Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete files that don't match a wildcard?

For example, I can delete all .exe files using the following wildcard:

del *.exe

How can I do the opposite, i.e. delete all files that do not end in .exe?

like image 713
nyuszika7h Avatar asked Feb 11 '11 18:02

nyuszika7h


1 Answers

You can try this.

FOR /R [directory] %%F IN (*.*) DO IF NOT "%%~xF" == ".[extension]" DEL /F /S "%%F"

Or, if you have only one .exe file, it’s even simpler.

for %i in (*.*) do if not %i == FILE.EXE del %i
like image 92
Arseny Avatar answered Nov 07 '22 19:11

Arseny