Monday, October 05, 2009

Finding and Deleting Files

Today, I was trying to remove a bunch of temporary files using the DOS command prompt on Windows Vista. What a pain in the butt!

Let's assume that I have a bunch of unwanted ".tmp" files in the sub-directory "subdir". The directory "subdir" also has other sub-directories containing more files that I would like to delete.

For those of you familiar with Linux, to find and delete files its as easy as the following command:
find ./subdir/ -name '*.tmp'-exec rm -f {} \;
Unfortunately, I couldn't muster something like that up on Windows Vista. I tried stuff like
dir /B /S | find ".tmp"
This produced the full path of the files that I no longer wanted. When I then tried to pipe those files to del, like
dir /B /S | find ".tmp" | del
Vista just said 'The syntax of the command is incorrect.'

To make a long story short, I was finally able to come up with the following:
for /R %i in ("*.tmp") do del %i
Do you have an alternative way of finding and deleting files?