Kyle Posted January 18, 2008 Posted January 18, 2008 I need a VBScript that will check if a folder exists and if so delete it and all its contents. I have a VBScript that will do it for a singe file and i am not sure ho to convert it so it will delete a folder and all its contents. THis is what i hav.... Call DeleteIfFound ("C:\Documents and Settings\All Users\Start Menu\Programs\Web Design\Macromedia\Macromedia Contribute 3.lnk") Function DeleteIfFound (FilePath) Dim Fso Set Fso = CreateObject ("Scripting.FileSystemObject") If Fso.FileExists (FilePath) Then Fso.DeleteFile (FilePath) End If Set Fso = Nothing Basically I have a RIS image and it contains software that is not site licensed, i don't want to create a nother image just for that. So I just want to dlete the folder and shortcuts from the 'all users' menu. End Function
GlennT Posted January 18, 2008 Posted January 18, 2008 You could use a batch file with this in it.... if exist "C:\Documents and Settings\All Users\Start Menu\Programs\Web Design\Macromedia" rmdir /S /Q "C:\Documents and Settings\All Users\Start Menu\Programs\Web Design\Macromedia" That should do the trick.
Iain Posted January 18, 2008 Posted January 18, 2008 (edited) Or if you really want to use vbscript: strPath = "C:\pathtofolder" DeleteFolder strPath Function DeleteFolder(strFolderPath) Dim objFSO, objFolder Set objFSO = CreateObject ("Scripting.FileSystemObject") If objFSO.FolderExists(strFolderPath) Then objFSO.DeleteFolder strFolderPath, True End If Set objFSO = Nothing End Function Edited January 18, 2008 by Iain 2
Grantx01 Posted June 30, 2014 Posted June 30, 2014 works great but I was wondering if you wanted to make it for multiple files in different location. How would you do it. Also once delete is there any way to recover. "I do not wanted it recovered ever" for example: C:\test1 D:\test3
LosOjos Posted July 1, 2014 Posted July 1, 2014 works great but I was wondering if you wanted to make it for multiple files in different location. How would you do it. Also once delete is there any way to recover. "I do not wanted it recovered ever" for example: C:\test1 D:\test3 As it's been written as a function, you just call the function on whichever paths you want. Files will be recoverable though, the only way you can absolutely make sure they're not recoverable would be to use a tool like Eraser to remove them. You could still script it in a BATCH file though.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now