Jump to content

Help needed with VB Script to delete folder and all files.


Recommended Posts

Posted

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

Posted

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.

Posted (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 by Iain
  • Thanks 2
  • 6 years later...
Posted

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

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

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