batch file to delete all files from a folder

November 11, 2010 at 11:36:35
Specs: Windows XP
Hi All,

How to write a batch file to delete all files from a folder except two files. The name of the files which I don't want to delete I can hardcode there names in the code.

Please help..

Thanks a lot for your help in advance.


See More: batch file to delete all files from a folder

Report •

#1
November 11, 2010 at 13:00:26
FOR /f %%a IN ('DIR /b "P:\a\t\h\*.*"') DO (
IF NOT "%%a"=="File1" (
IF NOT "%%a"=="File2" ECHO DEL "%%a"
)

That should work, Remove the "ECHO" on line three when you're sure it works.

Can I put a question here?


Report •
Related Solutions


Ask Question