Ask a Question

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

SOLVED
AshokKumarSahoo
Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

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

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

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

2 REPLIES 2
tristaanogre
Community Hero

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

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

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

AshokKumarSahoo
Contributor

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

@tristaanogre Your code is working fine.Thanks a lot Smiley Very Happy

cancel
Showing results for 
Search instead for 
Did you mean: