Zip压缩与解压

Zip压缩与解压改写了之前的VBS脚本而已
只是创建Shell对象进行解压缩,没什么特别的
压缩:

#include <file.au3>
#include <array.au3>
#include <string.au3>

Dim $SourceDir, $ZipFile
$SourceDir= @ScriptDir & "\1111.txt"
$ZipFile= @ScriptDir & "\test.zip"
Zip($SourceDir, $ZipFile)

Func Zip($mySourceDir, $myZipFile)
 Dim $PathArr, $Ftype, $szDrive, $szDir, $szFName, $szExt,$f, $objShell, $objSource, $objFolderItem, $objTarget, $intoptions
 $PathArr = _PathSplit($mySourceDir, $szDrive, $szDir, $szFName, $szExt)
;~ _ArrayDisPlay($PathArr,"路径拆分演示")
 If StringLen($szExt)=0 Then
 $Ftype = "Folder"
 ElseIf StringLen($szExt)>0 Then
 $Ftype = "File"
 Else
 MsgBox(4096,"错误","压缩源文件/文件夹路径出错!")
 Exit
 EndIf
 $f = _FileCreate($myZipFile)
 FileWrite($f,"PK"&chr(5)&chr(6)&_StringRepeat(chr(0),18))
 FileClose($f)
 $objShell = objcreate("shell.Application")
 Select
 Case $Ftype="Folder"
 $objSource = $objShell.NameSpace($mySourceDir)
 $objFolderItem = $objSource.Items()
 Case $Ftype="File"
 $objSource = $objShell.NameSpace($szDrive & $szDir)
 $objFolderItem = $objSource.ParseName($szFName & $szExt)
 EndSelect
 $objTarget = $objShell.NameSpace($myZipFile)
 $intoptions = 256
 $objTarget.CopyHere($objFolderItem, $intoptions)
 Do
 sleep(1000)
 Until $objTarget.Items.Count>0
EndFunc

解压:

#include <file.au3>
#include <array.au3>
;~ #include <string.au3>

Dim $ZipFile, $TargetDir
$ZipFile = "D:\autoit_test\UnZip.zip"
$TargetDir = "D:\autoit_test" 

UnZip($ZipFile,$TargetDir)

Func UnZip($myZipFile,$myTargetDir)
 Dim $objShell, $PathArr, $szDrive, $szDir, $szFName, $szExt, $objSource, $objFolderItem, $objTarget, $intOptions
 $objShell = ObjCreate("Shell.Application")
 $PathArr = _PathSplit($myZipFile, $szDrive, $szDir, $szFName, $szExt)
 _ArrayDisPlay($PathArr,"路径拆分演示")
 If Not(FileExists($myZipFile)) Then
 MsgBox(4096,"错误","解压缩源文件路径不存在!")
 Exit
 ElseIf Not($szExt=".zip") Then
 MsgBox(4096,"错误","解压缩源文件路径出错!")
 Exit
 ElseIf Not(FileExists($myTargetDir)) Then
 DirCreate($myTargetDir)
 EndIf
 $objSource = $objShell.NameSpace($myZipFile)
 $objFolderItem = $objSource.Items()
 $objTarget = $objShell.NameSpace($myTargetDir)
 $intOptions = 256
 $objTarget.CopyHere($objFolderItem,$intOptions)
EndFunc
© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容