MS-DOS command to delete all files except one

You can use the for and if commands to accomplish this:

for %i in (*) do if not "%~i" == a.c del "%~i"

This goes through the current directory, and compares each file name to a.c. If it doesn't match, the file is deleted.


You could set the file to read only before deleting everything

attrib +r a.c
del *.*
attrib -r a.c

No, there isn't. I'd make a directory, copy the important file into it, erase ., and move the file back. Then delete the temp file.

mkdir temp
move a.c temp
erase *.*
move temp\* .
rmdir temp

Tags:

Ms Dos