There is a shared folder in my D
drive as works
(D:\works
). I need to delete all the files in that folder and sub folders except word and excel files
in there. how can i do this ?
Asked
Active
Viewed 7,850 times
0

Bishan
- 15,211
- 52
- 164
- 258
-
try if `del /[!*.DOC !*.XLS] *` works.. Be in `D:/Works` folder first... – Fahim Parkar Feb 07 '12 at 03:52
-
@FahimParkar Your code is not working. got this error. `Invalid switch - "!*.DOC".` – Bishan Feb 07 '12 at 05:08
-
I don't think it's possible to exclude file patterns using del. See the answer I posted below, that should work. – Kai G Feb 07 '12 at 07:59
1 Answers
1
You could do something similar to what this guy's done: http://www.codesingh.com/2009/08/using-robocopy-to-delete-old-files-from.html
Something like this should work:
mkdir D:\_tempDelete
robocopy D:\works D:\_tempDelete /e /MOVE /XF *.xls* *.doc*
rmdir D:\_tempDelete /s /q
Provided you have permissions to create and delete folders on D:. Otherwise you could just move the files somewhere on your local drive and delete them from there.

Kai G
- 3,371
- 3
- 26
- 30
-
what is `robocopy` ? not working in my computer. `'robocopy' is not recognized as an internal or external command, operable program or batch file.` – Bishan Feb 07 '12 at 08:15
-
1It's standard in Vista and Win 7. Are you running XP? I think you can get it for XP - http://en.wikipedia.org/wiki/Robocopy – Kai G Feb 07 '12 at 08:30