使用 VBScript 检查 zip 文件中文件的属性 [英] Using VBScript to examine properties of files within a zip file

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

问题描述

我正在尝试使用 VBScript 来检查数百个 .zip 文件的内容.基本上我想做的是遍历每个 .zip 并找到该 zip 文件中的所有文件.对于 zip 中的每个文件,我想将有关它的一些信息记录到 Oracle 数据库中.该信息是:文件名和文件修改日期.

I'm trying to use VBScript to examine the contents of several hundred .zip files. Essentially what I want to do is run through each .zip and find all of the files wihtin that zip file. For each one of these files within the zip, I want to record some information about it to an Oracle database. That information being: file name and file modified date.

到目前为止,我的解决方案是将每个 zips 文件夹结构解压缩到一个临时文件夹,然后使用 fso 对象在临时文件夹中运行.然而,这已被证明是非常缓慢的.

So far, my solution has been extracting each zips folder structure to a temp folder then running through the temp folder with an fso object. However, this has been proven to be very slow.

有没有办法在不解压 zip 文件的情况下实现这一点?

Is there a way to accoplish this without unziping the zip files?

推荐答案

您可以使用 Shell 对象就地完成.但它可能会一样慢.如果只是名称和日期,Explorer 可能会直接从 zip 目录中获取它(在文件末尾,因此仍需要读取整个文件).

You can do it in place with Shell Objects. But it will be just as slow, maybe. If just name and date Explorer may get it direct from the zip directory (at the end of the file so the whole file still needs to be read).

这会将文件夹中的项目复制到另一个文件夹.一个 zip 文件是一个文件夹,所以它会复制进去和复制出来.

This copies items in a folder to another folder. A zip file is a folder so it will copy in and copy out.

压缩

Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")

Set SrcFldr=objShell.NameSpace(Ag(1))
Set DestFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Msgbox "Finished"

解压(注意SrcFolder和DestFolder是颠倒的)

To Unzip (note SrcFolder and DestFolder are reversed)

Set objShell = CreateObject("Shell.Application")
Set Ag=Wscript.Arguments
set WshShell = WScript.CreateObject("WScript.Shell")

Set DestFldr=objShell.NameSpace(Ag(1))
Set SrcFldr=objShell.NameSpace(Ag(0))
Set FldrItems=SrcFldr.Items
DestFldr.CopyHere FldrItems, &H214
Msgbox "Finished"

创建一个空白的 zip.(我应该使用 ADODB 二进制流而不是 FSO 文本流,但这应该无关紧要)

To Create a blank zip. (I should have used an ADODB binary stream rather than an FSO text stream, but it shouldn't matter)

Set Ag=Wscript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Ag(0), 8, vbtrue)
BlankZip = "PK" & Chr(5) & Chr(6)
For x = 0 to 17
    BlankZip = BlankZip & Chr(0)
Next
ts.Write BlankZip

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

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