您好我是批量构建我自己的防病毒软件并且想要添加拉链炸弹或减压炸弹检测功能,我如何确定批量或vbscript中zip的最终未压缩大小? 提前致谢
答案 0 :(得分:1)
将其另存为.bat
:
@if (@x)==(@y) @end /***** jscript comment ******
@echo off
cscript //E:JScript //nologo "%~f0" %*
exit /b 0
@if (@x)==(@y) @end ****** end comment *********/
var wshShell = WScript.CreateObject("WScript.Shell");
var args=WScript.Arguments;
var zipFile=args.Item(0);
getSize = function(path){
var ShellObj=new ActiveXObject("Shell.Application");
var targetObject = new Object;
var targetObject=ShellObj.NameSpace(path);
if (typeof size === 'undefined'){
var size=0;
}
if (targetObject != null ){
for (var i=0; i<targetObject.Items().Count;i++){
//WScript.Echo("Checking: "+targetObject.Items().Item(i));
if(!targetObject.Items().Item(i).IsFolder){
size=size+targetObject.Items().Item(i).Size;
} else if (targetObject.Items().Item(i).Count!=0){
size=size+getSize(targetObject.Items().Item(i).Path);
}
}
} else {
return 0;
}
return size;
}
WScript.Echo(getSize(zipFile));
它只需要一个参数 - zip文件并以字节为单位打印其大小。 (Item.Size
属性获得未压缩的大小)
编辑它不适用于相对路径。应使用全路径。 编辑 zipjs.bat(介绍here)可用于此目的:
call zipjs.bat getSize -source C:\\zipFile.zip
并且不再需要完整路径,可以使用相对路径。