Reputation: 113
We have a network share that has backups from multiple machines throughout the company. Once a quarter it gets copied off site and then we wipe out the contents. The share has a subdirectoy for each machine and then within that subdirectory are more folders with the backups. The machine subdirectory has sharing enabled and permissions set for that individual machine so we do not want to delete those but we do want to delete all the subdirectories. So it looks like this:
Machine 1
- My Documents
Machine 2
- My Documents
- Database Config
Machine 3
- My Documents
- Desktop
In the above example all the Machine directories are in a folder called Backups and we want to delete all the sub directories of them (My Docs, Database Config, Desktop, etc). There are about 190 machines so manually going into each directory then deleting the contents is very time consuming. This will preferably be a DOS based batch file that will be run manually by a admin. I've been playing with a For Do loop and can't get it to work as expected. Any suggestions?
Upvotes: 0
Views: 40
Reputation: 29339
use a FOR
command with the /D
option to iterate over all the directories in the network share. Then, for each directory found, use FOR /D
again to iterate over all the subdirectories and wipe out them with RD /S
something similar to this...
FOR /D %%a in (*) DO (
PUSHD "%%a"
FOR /D %%b in (*) DO RD /S /Q "%%b"
POPD
)
Upvotes: 1