Batch file 用于压缩同一目录中文件夹的批处理文件

Batch file 用于压缩同一目录中文件夹的批处理文件,batch-file,Batch File,我想使用批处理文件压缩文件夹。这是我的zip.bat代码: CScript zip.vbs E:\app E:\app.zip zip.vbs具有以下代码: Set objArgs = WScript.Arguments InputFolder = objArgs(0) ZipFile = objArgs(1) 'Create empty ZIP file. CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFil

我想使用批处理文件压缩文件夹。这是我的zip.bat代码:

CScript zip.vbs E:\app E:\app.zip
zip.vbs具有以下代码:

Set objArgs = WScript.Arguments

InputFolder = objArgs(0)

ZipFile = objArgs(1)

'Create empty ZIP file.

CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)


Set objShell = CreateObject("Shell.Application")

Set source = objShell.NameSpace(InputFolder).Items

objShell.NameSpace(ZipFile).CopyHere(source)

'Required!

wScript.Sleep 2000000
这段代码是ziiping文件夹正确,但我不想提及任何驱动器名。我想在任何驱动器,如果我保持我的bat文件n应用程序文件夹,然后运行bat文件后,它应该压缩文件夹。
是否有此方面的代码?

您需要添加
文件系统对象
并使用函数-shell。应用程序名称空间不接受相对路径

虽然使用睡眠是个坏主意-它会使脚本速度太慢或会中断压缩。更好的办法是计算源和目标中的项目,因为压缩是事务性的,而文件计数是检查操作是否完成的可靠方法

您还可以检查我的,它也使用Shell.Application,但所有内容都打包在混合
jscript\.bat
脚本中(它甚至不会创建临时文件)。它能够处理相对路径,并且相对健壮(我写过的最常用的脚本之一——因此我得到了一些反馈,需要修复大量的bug:-))

更多信息请点击此处:


你能分享一些简单的代码吗。。你提供的那个不是working@Dimple-zipjs.bat有问题吗?你能提供更多信息吗?我会更新我的答案。
Set objArgs = WScript.Arguments
set fso=CreateObject("Scripting.FileSystemObject"):
InputFolder =  fso.GetAbsolutePathName(objArgs(0)):



ZipFile = objArgs(1)

'Create empty ZIP file.

CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)


Set objShell = CreateObject("Shell.Application")

Set source = objShell.NameSpace(InputFolder).Items

objShell.NameSpace(ZipFile).CopyHere(source)

'Required!

wScript.Sleep 2000000