+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, Help needed with VB Script to delete folder and all files. in Coding and Web Development; I need a VBScript that will check if a folder exists and if so delete it and all its contents. ...
  1. #1
    Kyle's Avatar
    Join Date
    Jan 2006
    Posts
    969
    Thank Post
    91
    Thanked 14 Times in 13 Posts
    Rep Power
    20

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

    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

  2. #2
    GlennT's Avatar
    Join Date
    Sep 2006
    Location
    Zummmerzet!
    Posts
    249
    Thank Post
    19
    Thanked 17 Times in 16 Posts
    Rep Power
    19
    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.

  3. #3
    Iain's Avatar
    Join Date
    Oct 2006
    Location
    Warwickshire
    Posts
    178
    Thank Post
    27
    Thanked 87 Times in 49 Posts
    Rep Power
    30
    Or if you really want to use vbscript:

    Code:
    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
    Last edited by Iain; 18th January 2008 at 01:26 PM.

  4. 2 Thanks to Iain:

    Kyle (6th February 2008), projector1 (8th March 2008)

  5. #4
    Kyle's Avatar
    Join Date
    Jan 2006
    Posts
    969
    Thank Post
    91
    Thanked 14 Times in 13 Posts
    Rep Power
    20
    Thaks Iain that works perfectly

SHARE:
+ Post New Thread

Similar Threads

  1. Delete a folder using scripting
    By FN-GM in forum Scripts
    Replies: 15
    Last Post: 22nd December 2007, 04:44 PM
  2. Replies: 8
    Last Post: 17th November 2007, 09:04 PM
  3. Got a folder I cannot delete or take ownership of
    By sidewinder in forum Windows
    Replies: 2
    Last Post: 20th March 2007, 02:49 PM
  4. Replies: 1
    Last Post: 21st January 2007, 02:51 PM
  5. Replies: 3
    Last Post: 25th September 2006, 12:27 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
  •