Delete files in multiple directories using a batch file.

Where items have <> you need to enter the details in there to make it work. The code below searches specified location and its subdirectories for given files and then deletes them. To make this work you need to copy the code into a notepad text file and replace <path> and <file name> with the variables you require. Then you need to save the file as a .bat to allow it to run.

The Code

forfiles /p <path> /s /m <file name> /c "cmd /c del @path"

This code uses the forfiles command. To find out more information on the forfiles command, open up a command (dos) window and type forfiles /?. The above code seaches the directory specified (i.e replace <path> with where you want it to seach) and also looks in the subdirectories (/s). It applies a mask (/m) also known as search parameters. You replace <file name> with the file name you wish to be deleted and the last section performs a command (/ c cmd) which in this case is the delete function (del) of those files using its full path (@path).


This code can be used to fix the problem with a Windows 7 network where it renames the Home area on a network to "mydocuments" instead of their username. See here for information.


Disclaimer: By using any of the software mentioned in this document you are adhering to their terms and conditions of use. I do not accept any responsibility for any loss, damage or disruption to your data or computer system that may occur while using the software mentioned in this document.
Site Map | Privacy Policy | Contact Us
| Best viewed in 1024 * 768 or above | ©2008