gpt4 book ai didi

vbscript - 压缩文件夹

转载 作者:行者123 更新时间:2023-12-02 21:45:52 24 4
gpt4 key购买 nike

我正在尝试用 VBScript 压缩文件夹,但似乎不起作用。我确定我正确创建了头文件。

它正确创建实际文件,只是不压缩文件夹。

任何人有任何想法:

Sub ArchiveFolder (folder)

Dim fso, wShell, sApp, zipFile

Set fso = CreateObject("Scripting.FileSystemObject")
Set wShell = CreateObject("WScript.Shell")
Set sApp = CreateObject("Shell.Application")
Set zipFile = fso.CreateTextFile(folder & ".zip")

' Write zip file header.
zipFile.Write "PK" & Chr(5) & Chr(6) & String(18, 0)
zipFile.Close

sApp.NameSpace(folder & ".zip").CopyHere folder

End Sub

最佳答案

我找到的答案here 。神奇之处在于最后一个 Do..Loop,其中脚本等待 Shell 完成工作。

ArchiveFolder "sub\foo.zip", "..\baz"

Sub ArchiveFolder (zipFile, sFolder)

With CreateObject("Scripting.FileSystemObject")
zipFile = .GetAbsolutePathName(zipFile)
sFolder = .GetAbsolutePathName(sFolder)

With .CreateTextFile(zipFile, True)
.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, chr(0))
End With
End With

With CreateObject("Shell.Application")
.NameSpace(zipFile).CopyHere .NameSpace(sFolder).Items

Do Until .NameSpace(zipFile).Items.Count = _
.NameSpace(sFolder).Items.Count
WScript.Sleep 1000
Loop
End With

End Sub

关于vbscript - 压缩文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15139761/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com