如何使用 VBScript 读取 .zip 文件的内容而不实际解压文件?
我有一个以父目录开头的 .zip 文件。我需要从文件中读取该目录,然后搜索我的硬盘以查看该目录名称是否已存在。如果存在,我会将其删除并替换为 .zip 文件的内容。
所有这些我都可以做,除了读取 .zip 而不实际解压缩文件。
.zip 文件的大小可以超过 2G,因此我想避免解压,然后读取目录,然后复制。
我不直接解压到该位置并强制覆盖的原因是,由于某种原因,当使用 CopyHere 方法解压时,它会忽略通常强制覆盖的开关,并且仍然提示用户如果想要覆盖。
解压文件的代码:
Set objSA = CreateObject("Shell.Application")
Set objSource = objSA.NameSpace(pathToZipFile).Items ()
Set objTarget = objSA.NameSpace(extractTo)
objTarget.CopyHere objSource,4
I have a .zip file that starts with a parent directory. I need to read that dir from the file then search my HD to see if that dir name already exists. If it exists, I then delete it and replace it the contents of the .zip file.
All of this I can do, except read the .zip without actually unzipping the file.
The .zip file can be upwards of 2G in size so I want to avoid unzipping, then reading the dir, then copying.
The reason I don't just unzip directly to the location and force an overwrite is that for some reason when using the CopyHere
method to unzip, it ignores the switches that would normally force the overwrite and still prompts the user if they want to overwrite.
Code to unzip files:
Set objSA = CreateObject("Shell.Application")
Set objSource = objSA.NameSpace(pathToZipFile).Items ()
Set objTarget = objSA.NameSpace(extractTo)
objTarget.CopyHere objSource,4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在
objSource
对象上使用For Each
,例如:You can use
For Each
on yourobjSource
object, for example:这是关于 SO 的类似问题。
如何列出 .zip 文件夹的内容在 C# 中?
我自己使用过这个库。它运行良好,http://dotnetzip.codeplex.com/,甚至出现了一个树视图示例读取 zip 而不解压。
您将需要服务器上的 DLL,但我不会说您必须安装它们。 ;)
Here is a similar question on SO.
How to list the contents of a .zip folder in c#?
I've used this library myself. It works well, http://dotnetzip.codeplex.com/, there is even a treeview example that appears to read the zip without extraction.
You will need the DLLs on the server, but I wouldn't say you have to install them. ;)
假设您可以使用外部应用程序,请尝试下载 7Zip ,然后让您的脚本使用 <代码>-l开关。这应该会给你一些你应该能够以某种方式解析的输出。
帮助文件中的示例:
7z l archive.zip
Assuming that you can use an external application, try downloading 7Zip and then have your script execute it with the
-l
switch. This should give you some output that you should be able to parse in some way.Sample from the help file:
7z l archive.zip
我不确定是否可以在不解压的情况下读取 zip 的内容。
如果您只是想避免对数据进行耗时的复制操作,您可以尝试解压缩到临时目录,然后使用“移动”功能。移动通常比复制耗时更少,因为它实际上并不重写磁盘上的数据。它只是更新文件系统以指向数据所在的位置。
I'm not sure if it is possible to read the contents of a zip without extracting it.
If you are just trying to avoid a time consuming copy operation on the data you could try unzipping to a temp directory and then using a "move" function. Move is usually less time consuming than copy as it doesn't actually re-write the data on the disk. It just updates the file system to point at where the data is.