我找到的以下脚本正在压缩文件夹:
Set Args = Wscript.Arguments
source = Args(0)
target = Args(1)
ArchiveFolder source, target
Sub ArchiveFolder (sFolder, zipFile)
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
但是,在尝试压缩空子文件夹时。
我收到错误消息:
Windows was unable to add one or more empty directories...
我尝试添加一个条件,如果 sFolder 为空,请跳过复制,但结果相同。
If .NameSpace(sFolder).Items.Count <> 0 Then
.NameSpace(zipFile).CopyHere .NameSpace(sFolder).Items
Else
WScript.Quit
End If
想法?