Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to delete a folder from multiple directories 2

Status
Not open for further replies.

NikeGuy23

MIS
Jun 17, 2002
108
0
0
CA
Hi all not sure if this is the right Forum or not but I am going to try anyhow. I have a folder temp in multiple directories that I want to remove without having to go through one by one and manually doing it.
For example \\servername\users\test1\temp
\\servername\users\test2\temp
\\servername\users\test3\temp

I want to delete the temp directory from each of the test directories.
 
Something like this would probably work (not really tested thoroughly though):

Code:
@echo off
FOR /D %%d IN (*.*) DO (
        echo rmdir "%%d\temp"
)

That will remove the directories, but would have to be placed in \\servername\users and executed from there.

I'd strongly advise testing it first. I left the "echo" statement there so it doesn't do anything destructive. If you're just trying to delete a subset of what's in \\servername\users you'll have to find a wildcard to find them.
 
Actually, even better yet, you might be able to get away with this (again, removes from all directories):

Code:
@echo off
pushd "\\servername\users"
FOR /D %%d IN (*.*) DO (
        echo rmdir "%%d\temp"
)
popd

I've left the echo statement in so it's not destructive.

The pushd command temporarily maps a drive letter to the specified path and changes to it to execute all the commands. The FOR statement just loops through the directories and perform (in this case) the echo statement. The popd command remove the temporary drive mapping and reverts to whatever directory the script is stored in.
 
You could also have used the search functionality, select them and delete ...

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top