+ Post New Thread
Results 1 to 8 of 8
Scripts Thread, VB script to delete certain folders in Coding and Web Development; Hi I am after a VB script that will check all folders within a folder called G:\Profiles and delete those ...
  1. #1
    PTD
    PTD is offline

    Join Date
    Jun 2008
    Posts
    5
    Thank Post
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    VB script to delete certain folders

    Hi

    I am after a VB script that will check all folders within a folder called G:\Profiles and delete those that are have the name
    Username.Domain_nfrs

    We have slow replication and sometimes a user profile folder gets created twice, the second time with the _nfrs appended to the folder.

    I would like to delete this.

    Can anyone possibly help? and wouldn't mind explaining what each part does?

    Thanks

    I'm new to scriptin

  2. #2
    PTD
    PTD is offline

    Join Date
    Jun 2008
    Posts
    5
    Thank Post
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Angry

    Thanks, appreciate answer but for some reason these don't take care of themselves so we end up with a few replicated files.. hebce the need to delete them, we been doing it manually so far.. but it'ss a pain!!

  3. #3
    PTD
    PTD is offline

    Join Date
    Jun 2008
    Posts
    5
    Thank Post
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks but it doesn't seem to remove the folder.

  4. #4

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,037
    Thank Post
    209
    Thanked 425 Times in 306 Posts
    Rep Power
    144
    Try these two lines of VB script, they will remove all folders and their contents where the folder ends in _nfrs

    Code:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.DeleteFolder("G:\profiles\*_nfrs.*")
    mike.

  5. #5
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    Heres a vbs version of the same thing:

    Code:
    Dim Path
    Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
    
    Path = WScript.Arguments(0)
    
    DeleteFolders(Path)
    
    Public Function DeleteFolders(Byval Path)
    	Dim n: n = 0
    	Dim Folder: Set Folder = fso.GetFolder(Path)
    	DeleteFolder(Folder)
    	SearchSubfolder(Folder)
    
    	set Folder = nothing
    End Function
    
    Public Function SearchSubfolder(Folder)
    	dim SubFodlers: Set Subfolders = Folder.subfolders
    	dim Subfolder
    
    	For each Subfolder in Subfolders
    		DeleteFolder(SubFolder)
    		SearchSubfolder(Subfolder)
    	next
    	
    	set Subfolders = nothing
    End Function
    
    Public Function DeleteFolder(Folder)
    	Dim Files: Set Folders = Folder.subfolders
    	Dim i: i = Folders.Count
    	Dim CheckFolder
    	Dim CheckPath
    
    	For Each CheckFolder In Folders
    		If instr(checkfolder.name,"_nfrs") Then	
    			fso.deletefolder checkfolder.path
    		end if
    	Next
    	Set Folders = Nothing
    End Function
    Usage:
    In command prompt -
    cscript nameofscript.vbs "Path"
    eg
    cscript nameofscript.vbs "g:\profiles"

    NOTE: This will recursively search all folders in the root folder for folders with the name of "*_nfrs*" and delete it, use with care/at your own risk.
    Last edited by apeo; 4th June 2008 at 01:14 PM.

  6. Thanks to apeo from:

    PTD (4th June 2008)

  7. #6
    PTD
    PTD is offline

    Join Date
    Jun 2008
    Posts
    5
    Thank Post
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi

    It still doesn't delete the folder..

    I'm trying it on a test box at moment the username appears in Killprofile.txt but doesn't delete folder.


    Manic

    is that all i need or is there more??

  8. #7

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,037
    Thank Post
    209
    Thanked 425 Times in 306 Posts
    Rep Power
    144
    There's a GPO setting that allows you to let admin users have access to profiles as well as the user the profile belongs to. We have this set, and it solves a lot of problems with accessing stuff when we need to. It only works when the profile is created by the network for the first time however, so switching it on won't alter the permissions on profiles you already have. However you can run a XCALS command on the necessary folders to do this, but be careful as in my experience it's easy to mess up permissions on profile folders, then they won't work properly!

    That VBS script I posted should just work as is, as long as the user running it has access to the folder its deleting of course! Please test it somewhere non-critical first thou!

    Mike.
    Last edited by maniac; 4th June 2008 at 12:29 PM.

  9. Thanks to maniac from:

    PTD (4th June 2008)

  10. #8
    PTD
    PTD is offline

    Join Date
    Jun 2008
    Posts
    5
    Thank Post
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Brillaint, the script works

    Many Thanks to the both of you for your help.

SHARE:
+ Post New Thread

Similar Threads

  1. Script to delete certain folders
    By Pumaedition in forum Scripts
    Replies: 4
    Last Post: 22nd April 2008, 10:08 PM
  2. Replies: 2
    Last Post: 17th April 2008, 11:25 AM
  3. Replies: 5
    Last Post: 9th March 2008, 12:15 AM
  4. Wanted: VBScript to delete folders from C:
    By timbo343 in forum Scripts
    Replies: 7
    Last Post: 7th February 2008, 11:50 AM
  5. Replies: 15
    Last Post: 19th September 2007, 10:46 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
  •