+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
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 ...
  1. #1
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    3,017
    Thank Post
    304
    Thanked 288 Times in 200 Posts
    Rep Power
    120

    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

  2. #2

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    639
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324

    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.

  3. #3

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Needa script to delete specific multiple folders

    That's broken. You've not removed the registry entries.

  4. #4

    Join Date
    Feb 2006
    Location
    Derbyshire
    Posts
    1,381
    Thank Post
    181
    Thanked 211 Times in 171 Posts
    Rep Power
    65

    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.

  5. #5

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    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.

  6. #6
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    3,017
    Thank Post
    304
    Thanked 288 Times in 200 Posts
    Rep Power
    120

    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?

  7. #7

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    639
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324

    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.

  8. #8
    tosca925's Avatar
    Join Date
    Aug 2005
    Location
    Midlands
    Posts
    1,547
    Thank Post
    4
    Thanked 4 Times in 4 Posts
    Rep Power
    22

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

  9. #9
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    3,017
    Thank Post
    304
    Thanked 288 Times in 200 Posts
    Rep Power
    120

    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.

  10. #10
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42

    Re: Needa script to delete specific multiple folders

    Quote 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

  11. #11

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Needa script to delete specific multiple folders

    That's the one.

  12. #12

    tech_guy's Avatar
    Join Date
    May 2007
    Location
    That little bit in the middle of Little Old England
    Posts
    8,135
    Thank Post
    1,908
    Thanked 1,344 Times in 742 Posts
    Blog Entries
    3
    Rep Power
    395

    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)

  13. #13

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Needa script to delete specific multiple folders

    Machine hangs at 'Loading your personal settings' at login.

  14. #14

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    639
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324

    Re: Needa script to delete specific multiple folders

    That's odd, we've never had that problem.

  15. #15

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: Needa script to delete specific multiple folders

    I have though.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Script to Delete Profiles - PLEASE HELP
    By Mr_M_Cox in forum Scripts
    Replies: 13
    Last Post: 22nd February 2013, 03:53 PM
  2. Replies: 3
    Last Post: 26th October 2012, 02:15 PM
  3. need a script to delete shortcuts
    By philtomo-25 in forum Scripts
    Replies: 2
    Last Post: 1st November 2007, 03:50 PM
  4. Replies: 9
    Last Post: 10th May 2007, 10:13 AM
  5. Replies: 4
    Last Post: 15th December 2006, 12: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
  •