Jump to content

Recommended Posts

Posted

Hi,

 

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!!!!!! :(

Posted

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:

 

cd..

 

cd..

 

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:

 

X:\Users\Home Folders\USERNAME1$

X:\Users\Home Folders\USERNAME2$

X:\Users\Home Folders\USERNAME3$

X:\Users\Home Folders\USERNAME4$

 

Use the edit menu and choose to replace:

 

In the find box enter:

 

X:\Users\Home Folders\

 

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..

  • Thanks 1
Posted

The suggestions look good to me, but I always

forget to put quotes around the directory names

and some of the names have spaces in them.

 

Do this:

rd "Folder To Remove"

 

Instead of:

rd Folder To Remove

 

Mike Honeycutt

UNC Asheville

Posted

Thanks for teaching an old dog a new trick - I've never heard of this feature.

 

Now that I'm an "expert", I might suggest:

 

1. CMD prompt

2. EDIT killfile.txt in case mistakes occur that need to be fixed.

 

Thanks again for the tip

 

Mike Honeycutt

  • 4 weeks later...
Posted
It's also useful if you've got a command-line window open and you want to change directory to something like "c:\my stuff\this directory name is so long i dont think i could type it in again without making a mistake".

 

You could just start writing the folder name and use tab!!:)

 

Sorry couldn't help it.

Posted

Some may find this handy....

You will need to compile it first - [ I did it in AutoIT ]

When run it will delete all the files & folders in the directory apart from the folder 'keep me'

I run this every year on our students home directories.

 

$search = FileFindFirstFile("*.*")
; Check if the search was successful
If $search = -1 Then
   MsgBox(0, "Error", "No files/directories matched the search pattern")
   Exit
EndIf

While 1
   $file = FileFindNextFile($search)
   If @error <> 0 Then ExitLoop
   If $file = "keep me" Then ContinueLoop
   If $file = "." Or $file = ".." Then ContinueLoop
   If StringInStr(FileGetAttrib(@SCRIPTDIR & "\" & $file) , "D") Then
       DirRemove($file, 1)
   Else
       FileDelete(@SCRIPTDIR & "\" & $file)
   EndIf
WEnd
FileClose($search)

 

If you want a compiled version - just ask and I'll copy it up...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...