Scripts Thread, Needa script to delete specific multiple folders in Coding and Web Development; Can anyone advise me on how to delete multiple folders from docs and settings, but am wanting the script to ...
-
19th September 2007, 10:30 AM #1 Needa script to delete specific multiple folders
Can anyone advise me on how to delete multiple folders from docs and settings, but am wanting the script to keep: All Users; Administrator; Default User and sophos.
So far i have the basic:
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSODeleteFolder("C:\.....") What do i need to add from here?
Thanks
-
-
IDG Tech News
-
19th September 2007, 10:45 AM #2 Re: Needa script to delete specific multiple folders
Here's a full script we use to remove profiles from Docs&Settings.
Code:
On Error Resume Next
Dim obtainfolder
Dim Pathfinder
Dim strPath
Set fso = CreateObject("Scripting.FileSystemObject")
strPath = "C:\Documents and Settings\"
set excludefile = fso.OpenTextFile("\\bbs-svr-001\rmpublic\scripts\exclude.txt", 1)
excludelist = excludefile.Readall
'msgbox excludelist
Set f = fso.GetFolder(strPath)
' Loop through all subfolders
For Each fldrItem in f.SubFolders
fldrName = fldrItem.name
If Right(strPath,1) <> "\" Then
Pathfinder = strPath & "\" & fldrName
Else
Pathfinder = strPath & fldrName
End If
If InStr(1, excludelist, fldrName, 1) Then
'msgbox "Has not deleted " & fldrName
Else
'msgbox "Deleting " & fldrName
set obtainfolder = fso.GetFolder(Pathfinder)
obtainfolder.Delete true
End If
'End Select
Next
' Clean up objects
Set fso = Nothing
Set fc = Nothing \\bbs-svr-001\rmpublic\scripts\exclude.txt contains a list of folders NOT to delete.
-
-
19th September 2007, 10:57 AM #3 Re: Needa script to delete specific multiple folders
That's broken. You've not removed the registry entries.
-
-
19th September 2007, 10:59 AM #4 Re: Needa script to delete specific multiple folders
I use a 1 line batch file, never got to grips with that new fangled VB script :P This only saves the All Users and Default User folder, but it should be apparent how to add others with another IF NOT.
for /D %I IN ("C$\documents and settings\*") do @IF NOT "All Users"=="%~nI" IF NOT "Default User"=="%~nI" rmdir "%I" /s /q | echo %I
With an extra FOR loop, you can have it run through a whole batch of remote machines in an ICT suite and do it from your workstation on demand...
for /L %V in (1,1,9) DO for /D %I IN ("\\ict2-%V\C$\documents and settings\*") do @IF NOT "All Users"=="%~nI" IF NOT "Default User"=="%~nI" rmdir "%I" /s /q | echo %I
Runs through ICT2-1 to ICT2-9 via UNC paths.
-
-
19th September 2007, 11:02 AM #5 Re: Needa script to delete specific multiple folders
That's also broken. You must remove the registry entries for the profile when you remove the folder.
-
-
19th September 2007, 11:24 AM #6 Re: Needa script to delete specific multiple folders
so if i didnt want to delete the following folders: All Users; Administrator; Default User and sophos, where would i put these in the script. Is it easier to call a txt file like you have done? Also, what is the excludefile.readall? Is that a file that you have created?
-
-
19th September 2007, 11:26 AM #7 Re: Needa script to delete specific multiple folders
Works OK for us. Which registry keys are you referring to specifically?
Yes, just put "All Users; Administrator; Default User and sophos" in a text file (one per line) and specify the path to it as the exclude file.
-
-
19th September 2007, 11:41 AM #8 Re: Needa script to delete specific multiple folders
Save below in a vbs file.
Please make sure you do not use this on staff laptops if they have a local user account becasue this will delete all their files.
USE THIS SCRIPT WITH CARE......
Function Main()
On Error Resume Next
Dim obtainfolder
Dim PathFolder
Dim strPath
Set fso = CreateObject("Scripting.FileSystemObject")
strPath = "C:\Documents and Settings\"
Set f = fso.GetFolder(strPath)
' Loop through all subfolders
For Each fldrItem in f.SubFolders
fldrName = fldrItem.name
If Right(strPath,1) <> "\" Then
PathFolder = strPath & "\" & fldrName
Else
PathFolder = strPath & fldrName
End If
Select Case fldrName
Case "Administrator":
Case "All Users":
Case "Default User":
Case "Sophos"
Case Else:
set obtainfolder = fso.GetFolder(PathFolder)
obtainfolder.Delete true
End Select
Next
' Clean up objects
Set fso = Nothing
Set fc = Nothing
End Function
call Main()
-
-
19th September 2007, 11:49 AM #9 Re: Needa script to delete specific multiple folders
Whay, thanks. Nah i shallnt be using this on laptops, its for the techs so if they mess up an image or something is missing from an image it will delete any local profles the kids have created.
-
-
19th September 2007, 11:58 AM #10 Re: Needa script to delete specific multiple folders

Originally Posted by
webman Works OK for us. Which registry keys are you referring to specifically?
I believe hes talking about:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
-
-
19th September 2007, 12:23 PM #11 Re: Needa script to delete specific multiple folders
-
-
19th September 2007, 12:30 PM #12 Re: Needa script to delete specific multiple folders
Ok I'm being thick here - what would happen if you deleted the folders but left the registry alone?
(we always delete both btw when we purge systems)
-
-
19th September 2007, 12:38 PM #13 Re: Needa script to delete specific multiple folders
Machine hangs at 'Loading your personal settings' at login.
-
-
19th September 2007, 01:11 PM #14 Re: Needa script to delete specific multiple folders
That's odd, we've never had that problem.
-
-
19th September 2007, 01:19 PM #15 Re: Needa script to delete specific multiple folders
I have though.
-
SHARE:
Similar Threads
-
By philtomo-25 in forum Scripts
Replies: 2
Last Post: 1st November 2007, 04:50 PM
-
By tosca925 in forum Scripts
Replies: 1
Last Post: 1st November 2007, 01:31 AM
-
By Mr_M_Cox in forum Scripts
Replies: 10
Last Post: 13th June 2007, 03:51 PM
-
By sidewinder in forum Scripts
Replies: 9
Last Post: 10th May 2007, 10:13 AM
-
By sidewinder in forum Windows
Replies: 4
Last Post: 15th December 2006, 01:14 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules