+ Post New Thread
Results 1 to 6 of 6
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
    974
    Thank Post
    91
    Thanked 14 Times in 13 Posts
    Rep Power
    21

    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
    20
    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
    188
    Thank Post
    28
    Thanked 93 Times in 53 Posts
    Rep Power
    32
    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
    974
    Thank Post
    91
    Thanked 14 Times in 13 Posts
    Rep Power
    21
    Thaks Iain that works perfectly

  6. #5

    Join Date
    Jun 2014
    Posts
    1
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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

  7. #6

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,511
    Thank Post
    1,457
    Thanked 1,206 Times in 818 Posts
    Rep Power
    723
    Quote Originally Posted by Grantx01 View Post
    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.

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
  •