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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete a List of Folders on Multiple Worlstations

Status
Not open for further replies.

sotghalz

Technical User
Apr 11, 2007
57
US
I have a list of computername\folderpaths (\\computername\c$\Documents and Settings\Username\My Documents\My Music\XXX\) in an excel document and I would like to have the script to reference the excel doc and delete the list of folders.

I have been working with:

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.Delete("Path")

Sometimes it works and sometimes I get permissions errors. Any help would be greatly appreciated.
 
Permissions errors are caused by insufficient rights. Make sure that your account is a local admin of the workstation.

Also verify that you are not being blocked by Windows Firewall, or a lack of File/Print Sharing being set on the NIC.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
All of our workstations are imaged and should have our security admin group on as local admins...I will have to double check them as needed.

How do I get the above code to reference a list of paths in a seperate file?
 
That part is easy. Refer to my FAQ faq329-4871

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
I have a better idea but I'm still getting errors with this script. I get a "path not found" error and I'm 100% postive the folder is there. Here is the code:

Code:
'On Error Resume Next

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = WScript.CreateObject("wscript.shell")
'If not oFSO.FileExists("wslist.txt") THEN
'wscript.echo "Please create a file named 'wslist.txt' with a list of \\computername\path,"&_
'vbcrlf&"with a hard return at the end of each line."
'wscript.quit
'end if

Set oTextStream = oFSO.OpenTextFile("wslist.txt")

RemotePC = Split(oTextStream.ReadAll, vbNewLine)

oTextStream.Close

For Each strComputer In RemotePC

[COLOR=red]Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder()[/color]
	
Next
 
A starting point:
Code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
For Each strFolder in Split(oFSO.OpenTextFile("wslist.txt").ReadAll, vbNewLine)
  oFSO.DeleteFolder strFolder, True
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
One last question...

How do I have the above script create a file that will let me know what was deleted?
 
One last question for you....have you done ANY research on VBScript? What have you tried so far? You need to research and look at error capturing.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Yes...but vb is not my expertise, obviously! Thanks for the help.
 
Look into the following FSO methods:
CreateTextFile / OpenTextFile, and WriteLine
 
Guitarzan, thanks for pointing me in the right direction.
 
The above will write to the file but not tell you if it was executed properly, hence my suggestion to look up error capturing.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
It is also worth pointing out that if any of your client PCs are running Vista then this code will fail because "Documents and Settings" is not a real folder - and you'll get some form of access error (depending on what operation you are trying).
 
Thanks for all your input. I ended up with this:

Code:
dim oFSO
dim log_file
dim fname
Const ForAppending = 8 

On Error Resume Next
fName = "path" & "log_" & Year(now) & "_" & Month(now) & "_" & Day(now) ".txt"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set log_file = oFSO.OpenTextFile(fName, ForAppending, True) 

For Each strFolder In Split(oFSO.OpenTextFile("wslist.txt").ReadAll, vbNewLine)
    oFSO.Deletefolder strFolder, TRUE
    If Err.number = 0 Then
        log_file.writeline("Deleted " & strFolder)
    Else
        log_file.writeline("Attempt to delete '" & strFolder & "' failed - " & Err.Description )
        Err.Clear
    End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top