using a batch file, how can I delete all files that are not in the Windows directory?

advertisements

i have a litle project for which i would like to remove all files outside of and not needed by the c:\windows operating system. therefore i need to create a list of what i want to keep i.e. boot.ini c:\windows etc and then delete everything else. i have seen examples using forFile, but i can be sure that extension will be on the machine. does anyone have any ideas how i can create the exclude list and then do the delete?


Don't forget to backup whichever method you implement.

:: you can define parameters so it know not include the folders you don't want and check it like so

IF "%2" == ""
IF "%1" == "RunMyBatchFile" ^

FOR %%i IN (""%filter%) ^  ::directory name goes in here that you want to iterate over todelete
DO (^::Do your stuff, make sure to use echo to see the output on the cmd
) ^