0
votes

I am trying to use a VBScript to delete a folder that is zipped. The zip file has other folders and files as well.

Edit begin: the base code is from: How to delete files from zip with VBScript end edit

Here is a localized sample of the script I tried deleting it with:

zipfile = "D:\testFolder\zippers\TestIt\New folder\your.zip"
foldername   = "New folder"
destination     = "D:\testFolder\zippers\TestIt\New folder"

Set app = CreateObject("Shell.Application")
For Each f In app.NameSpace(zipfile).Items
  If f.Name = foldername Then
    app.Namespace(destination).MoveHere f, FOF_NOCONFIRMATION
  End If
Next

Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFolder fso.BuildPath(destination, foldername), True

Sadly, the folder in the ZIP remains. So the MoveHere seems like a CopyHere instead... weird

Can Anybody help? PS: there is no delete-folder tag, just a delete-file one...

1

1 Answers

2
votes

It would be nice if you gave proper attribution when you're copying someone else's code.

With that said, it doesn't look like the Shell.Application object is capable of removing folders from a zip archive. Calling MoveFile on a folder moves all files from that nested folder out of the archive, but leaves an empty (sub)folder tree.

To remove the nested folder entirely you need to use 3rd party tools like 7-zip:

Function qq(s) : qq = """" & s & """" : End Function

Set sh = CreateObject("WScript.Shell")
sh.Run "C:\path\to\7z.exe d " & qq(zipfile) & " " & qq(foldername), 0, True