0

我有创建压缩文件夹的代码,下面的代码用于压缩文件

$ZipArchive = @ScriptDir & "\test.zip"; Put here the full path and name ame of archive you would like to create
$AddFile = @ScriptDir & "\zip.au3"; Put here the the File you would like to compress in the zip   
$AddFile2 = "c:\config.sys"; Take another File ...

$oShell = ObjCreate("Shell.Application"); 创建 s shell 对象

if IsObj($oShell) then                          
    InitZip($ZipArchive); Create an emtpy zip file with header      
    $oDir = $oShell.NameSpace($ZipArchive); Use the zip file as an "Folder"
    $oDir.CopyHere ($AddFile); Copy a file in the "Zip Folder" 
    $oDir.CopyHere ($AddFile2); Copy a second file
    sleep (500); Give the Objekt a litte bit time to work 
else 
    Msgbox (0,"Error","Error creating Object.")
endif 

Func InitZip ($zip_path_name)
    $init_zipString= Chr(80) & Chr(75) & Chr(5) & Chr(6);Create the Header String 
        for $n =1 to 18;the     
            $init_zipString= $init_zipString & Chr(0);Header    
        next 
    $file =FileOpen($zip_path_name,2)                       
    FileWrite($file,$init_zipString);Write the string in a file 
    FileClose($file)
EndFunc
4

1 回答 1

0

我建议通过 Run命令使用例如7z 。

将一个文件夹压缩成存档的命令如下所示:

7z a -r archive.7z directory

AutoIt中,这将是

local $command = "7z a -r archive.7z directory"
Run(@ComSpec & " /c " & $command, @ScriptDir)

如果 7z 目录未包含在全局路径变量中,您可能还需要指定 7z 可执行文件的路径。

于 2013-01-30T16:10:01.967 回答