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

Script To Remove/Delete Folders

Status
Not open for further replies.

TimothyMalloy

IS-IT--Management
Apr 11, 2006
8
US
Howdy all...

I have been poking around in here for a few days looking for help with my situation, but with no luck. I am a real noob to srcipting (I can barely spell script).

Here's the skinny: I'm looking for a script to REMOVE or DELETE a folder called "CDTower" from every user's desktop in my domain. Everything I've tried fails to complete the task...and I am hoplessly inept.

Any advice is sincerely appreciated.

Tim
 
You need to use the FileSystemObject DeleteFolder method.

Code:
oFolder = "C:\CDTOWER"
Set oFSO = CreateObject("Scripting.FileSystemObject")

If oFSO.FolderExists(oFolder) Then
   oFSO.DeleteFolder(oFolder)
End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
'are you sure its a folder and not a shortcut or .lnk file?
'might need
Set WshShell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
strFolder = WshShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop\CDTower"

If oFSO.FolderExists(strFolder) Then
oFSO.DeleteFolder(strFolder)
End If
 
THanks guys...that worked great...for me. I forgot to mention our users have no local admin priviliges. So please allow me to restate my question with one addition: How can I get my users to delete a folder call CDTower from their profile's desktop when they log on?

And would making the script a startup script for each machine change the way it is applied?

Thanks!

Tim
 
Nevermind...

I applied it to my workstation gpo as a startup script and it worked like a charm. Thanks so much for your help!

I'm needy so you'll hear from me again.

Tim
 
Timothy, I'm not sure which solution helped you or if both did. I see you are new tot he site so I just want to remind you that if a solution was helpful the polite thing to do is to click the link to thank the person for their valuable post. This issues the "purple star" and helps others browsing the site identify advice that was helpful.



I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top