Jump to content

Needa script to delete specific multiple folders


Recommended Posts

Posted

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:

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSODeleteFolder("C:\.....")

What do i need to add from here?

 

Thanks

Posted

Here's a full script we use to remove profiles from Docs&Settings.

 

	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.

Posted

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.

Posted
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?
Posted

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.

Posted

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()

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

Posted

I wonder if credential caching makes the difference? Whatever, cleaning up the associated reg keys is neater.

 

All you need then is some elusive magic to make any orphaned "hsperf" files and the like go away - things with nasty NTFS permissions requiring take ownership, files with illegal names etc.

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