views:

214

answers:

1

I have a script to delete all subfolders and files in a folder:

FOR /D %%i IN ("D:\myfolder\*") DO RD /S /Q "%%i" DEL /Q "D:\myfolder\*.*"

And it works great! Only problem is that I would like to exclude one or more folders, like the XCOPY exclude feature.

I just cant figure how I could add that to the script.

+1  A: 

You could try to hide the folders before the for-loop, and unhide them afterwards, like this:

ATTRIB +H D:\myfolder\keepit
FOR /D %%i IN ("D:\myfolder\*") DO RD /S /Q "%%i" DEL /Q "D:\myfolder\*.*"
ATTRIB -H D:\myfolder\keepit
Patrick
Wow! Works perfect! :-)
Thomas K