Script to delete specific folders
I am new to scripting! Please excuse me if I display any dumbness over the post!
I am interning in a company now and I have a problem. A large number of Home shares for users were retained by the company due to legal reasons. Now they 've decided to get rid of home drives that belonged to certain users... about 2000 of them. These hidden folders are over different remote servers. I can prepare an excel or txt with the paths of all these folders. I need a script that can pick these paths one-by-one and delete entire folders along with sub-folders.
I have a super-admin account so access wont be an issue.
Please help!!!!!! :(
Remove directorie with batch file:
The command for this should be something like this (as long as you are working from the machine your directories reside on) if Iím not mistaken:
RMDIR X:\YOURPATHNAME\HOMEFOLDER$ /s /q
/s being to remove all subdirectories
/q being to do it without confirmation
Note that you cannot be inside the directory that you are deleting; else you will be prompted with the message "The process cant access the folder because it is being used by another process".
If your text file is prepared as follows (and the majority of your home folders reside in one or two locations then you could do the following:
Imagine this is a few lines of your text file:
Use the edit menu and choose to replace:
In the find box enter:
In the replace box enter:
RMDIR X:\Users\Home Folders\
Then choose replace all:
Repeat this for any other locations you might have then concentrate on adding the switches Ė again by using find and replace.
In the find box choose to find a $ sign and choose to replace it with $ /s /q
(Obviously your directories need to end in $ signs)Ö
Now save the text file as a .bat file.
The script should then do the rest when you run it. Needless to say be sure you are targeting the right folders, Iím sure someone here will point out if Iíve made any mistakes with this..