VBS从压缩文件夹中删除文件夹 [英] VBS delete folder from Zipped folder

查看:44
本文介绍了VBS从压缩文件夹中删除文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 VBScript 删除压缩的文件夹.zip 文件还有其他文件夹和文件.

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

编辑开始:基本代码来自:如何使用 VBScript 从 zip 中删除文件结束编辑

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

遗憾的是,ZIP 中的文件夹仍然存在.所以 MoveHere 看起来更像是 CopyHere ......很奇怪

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

有人可以帮忙吗?PS:没有删除文件夹标签,只有一个删除文件...

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

推荐答案

如果你在复制时给出适当的署名就好了 别人的代码.

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

话虽如此,Shell.Application 对象似乎无法从 zip 存档中删除文件夹.对文件夹调用 MoveFile 将所有文件从该嵌套文件夹移出存档,但留下一个空的(子)文件夹树.

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.

要完全删除嵌套文件夹,您需要使用 7-zip 等 3rd 方工具::>

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

这篇关于VBS从压缩文件夹中删除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆