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 ...
-
4th June 2008, 09:44 AM #1
- 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
-
-
IDG Tech News
-
4th June 2008, 10:31 AM #2
- Rep Power
- 0
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!!
-
-
4th June 2008, 11:39 AM #3
- Rep Power
- 0
Thanks but it doesn't seem to remove the folder.
-
-
4th June 2008, 12:05 PM #4 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.
-
-
4th June 2008, 12:11 PM #5 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.
-
-
4th June 2008, 12:13 PM #6
- 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??
-
-
4th June 2008, 12:26 PM #7 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.
-
-
4th June 2008, 12:30 PM #8
- Rep Power
- 0
Brillaint, the script works
Many Thanks to the both of you for your help.
-
SHARE:
Similar Threads
-
By Pumaedition in forum Scripts
Replies: 4
Last Post: 22nd April 2008, 10:08 PM
-
By JPhillips173 in forum Scripts
Replies: 2
Last Post: 17th April 2008, 11:25 AM
-
By projector1 in forum Scripts
Replies: 5
Last Post: 9th March 2008, 01:15 AM
-
By timbo343 in forum Scripts
Replies: 7
Last Post: 7th February 2008, 12:50 PM
-
By timbo343 in forum Scripts
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
-
Forum Rules