Vbscript 用于压缩空文件夹上的文件错误的VBS脚本
我在某处找到的以下脚本正在压缩文件夹:Vbscript 用于压缩空文件夹上的文件错误的VBS脚本,vbscript,zip,Vbscript,Zip,我在某处找到的以下脚本正在压缩文件夹: Set Args = Wscript.Arguments source = Args(0) target = Args(1) ArchiveFolder source, target Sub ArchiveFolder (sFolder, zipFile) With CreateObject("Scripting.FileSystemObject") zipFile = .GetAbsolutePathName(zipFile
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无法添加一个或多个空目录…
我尝试添加一个条件,如果s文件夹为空,则跳过复制,但结果相同
If .NameSpace(sFolder).Items.Count <> 0 Then
.NameSpace(zipFile).CopyHere .NameSpace(sFolder).Items
Else
WScript.Quit
End If
If.NameSpace(sFolder.Items.Count 0然后
.NameSpace(zipFile).CopyHere.NameSpace(sFolder).Items
其他的
WScript.Quit
如果结束
Ideas?
.NameSpace(sFolder).Items.Count 0
将结果为true,但sFolder
可能包含空的子文件夹?也许这就是问题所在。.NameSpace(sFolder).Items.Count是否也引用子文件夹?.NameSpace(sFolder).Items.Count 0
将导致true,但sFolder
可能包含空子文件夹?也许这就是问题所在。.NameSpace(sFolder).Items.Count是否也引用子文件夹?