如何使用VBScript从zip文件中删除文件 [英] How to delete files from zip with VBScript

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

问题描述

我对 VBScript 非常陌生(这是我第一次使用它).到目前为止,我已经复制并改变了我的方式来达到我的目标.

Im very new to VBScript (this is my first time ever using it). So far I've copied and altered my way into getting as far as I am.

我有一个太大的 APK 文件,无法满足我的需要.所以我一直在做的是手动将其更改为 zip,然后从中删除几个图像,然后将其重命名为 APK.我试图用 VBScript 自动化.到目前为止,我有

I have an APK file that is too big for my needs. So what I've been doing is manually changing it to a zip and then deleting a couple images from it then renaming it back to an APK. Im trying to automate that with a VBScript. So far I have

Set oShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
sFolder = WORKSPACE & "\temp\" & app & "\build\" & PLATFORMSUBFOLDER & "\dist\" & app & "\bin"
oShell.CurrentDirectory = sFolder 

'Make the Apk a Zip.
fso.MoveFile apkfile, zipApk

这一切正常,我可以在 Windows 资源管理器中看到 APK 像我想要的那样更改为 zip.所以我想知道是否有任何快速的方法可以进入并删除几个文件而不提取整个文件?

This is all working and I can see in Windows Explorer that the APK changes to a zip like I want it to. So Im wondering if there is any quick ways to just go in and delete a couple files without extracting the whole thing?

如果没有,有没有一种简单的方法可以提取文件并同时解析它们?

If not is there an easy way to extract the files and parse them at the same time?

我看过这里 使用 VBScript 从 ZIP 文件中提取文件但似乎无法让它工作.我不断收到错误需要对象:'objShell.Names(...)'"是否有任何提示为什么会发生这种情况?

Ive looked here Extract files from ZIP file with VBScript but cant seem to get it working. I keep getting error "Object required: 'objShell.Names(...)'" Any hints to why this is happening?

推荐答案

使用 MoveHere 方法将项目移出 zip 文件:

Use the MoveHere method to move an item out of the zip file:

zipfile = "C:\path\to\your.zip"
fname   = "some.file"
dst     = "C:\some\folder"

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

然后从dst文件夹中删除文件:

Then delete the files from the dst folder:

Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile fso.BuildPath(dst, fname), True

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

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