Forum Discussion

AshokKumarSahoo's avatar
AshokKumarSahoo
Contributor
8 years ago

How to delete zip folders under a normal folder in vbscript?

Here below codes delete only normal folders under  'DownloadEDGARHTML' folder.My requirement is need to delete all zipfolders(lets say more than 2  zip folders).Please let me know vbscript code for this scenario.

 

StrFolderPath="C:\Project\Test Data\DownloadEDGARHTML\"

Dim ObjFSO
Set ObjFSO=CreateObject("Scripting.FileSystemObject")

For Each folder In ObjFSO.GetFolder(StrFolderPath).SubFolders
    folder.Delete
Next

  • Zip folders aren't exactly folders.  So, I don't think calling the SubFolders property of the GetFolder method will work.

     

    Using the built in aqFileSystem object, I'd recommend something more like this to get your collection

     

    For Each file in aqFileSystem.FindFiles(StrFolderPath, '*.zip', false)
        file.Delete
    Next
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Zip folders aren't exactly folders.  So, I don't think calling the SubFolders property of the GetFolder method will work.

     

    Using the built in aqFileSystem object, I'd recommend something more like this to get your collection

     

    For Each file in aqFileSystem.FindFiles(StrFolderPath, '*.zip', false)
        file.Delete
    Next