[오토핫키] 압축 및 압축해제 / Zip to File , File to Zip
#NoEnv
SetWorkingDir, %A_ScriptDir%
;SmartZip("test.zip", "dir2") ; Unpack a number of ZIP files to dir2
; Support flexible form of parameters
SmartZip("dir2", "testdir.zip") ; Pack the whole folder to ZIP file
;~ SmartZip("*.ahk", "scripts.zip") ; Pack ahk scripts of the working dir
;~ SmartZip("*.zip", "package.zip") ; Pack a number of ZIP files to one
;~ SmartZip("*.zip", "dir2") ; Unpack a number of ZIP files to dir2
;~ SmartZip("*.zip", "") ; Unpack to the working dir
return
;; --------- THE FUNCTION ------------------------------------
/*
SmartZip()
Smart ZIP/UnZIP files
Parameters:
s, o When compressing, s is the dir/files of the source and o is ZIP filename of object. When unpressing, they are the reverse.
t The options used by CopyHere method. For availble values, please refer to: http://msdn.microsoft.com/en-us/library/windows/desktop/bb787866
Link:
http://www.autohotkey.com/forum/viewtopic.php?p=523649#523649
*/
SmartZip(s, o, t = 4)
{
IfNotExist, %s%
return, -1 ; The souce is not exist. There may be misspelling.
oShell := ComObjCreate("Shell.Application")
if (SubStr(o, -3) = ".zip") ; Zip
{
IfNotExist, %o% ; Create the object ZIP file if it's not exist.
CreateZip(o)
Loop, %o%, 1
sObjectLongName := A_LoopFileLongPath
oObject := oShell.NameSpace(sObjectLongName)
Loop, %s%, 1
{
if (sObjectLongName = A_LoopFileLongPath)
{
continue
}
ToolTip, Zipping %A_LoopFileName% ..
oObject.CopyHere(A_LoopFileLongPath, t)
SplitPath, A_LoopFileLongPath, OutFileName
Loop
{
oObject := "", oObject := oShell.NameSpace(sObjectLongName) ; This doesn't affect the copyhere above.
if oObject.ParseName(OutFileName)
break
}
}
ToolTip
}
else if InStr(FileExist(o), "D") or (!FileExist(o) and (SubStr(s, -3) = ".zip")) ; Unzip
{
if !o
o := A_ScriptDir ; Use the working dir instead if the object is null.
else IfNotExist, %o%
FileCreateDir, %o%
Loop, %o%, 1
sObjectLongName := A_LoopFileLongPath
oObject := oShell.NameSpace(sObjectLongName)
Loop, %s%, 1
{
oSource := oShell.NameSpace(A_LoopFileLongPath)
oObject.CopyHere(oSource.Items, t)
}
}
}
CreateZip(n) ; Create empty Zip file
{
ZIPHeader1 := "PK" . Chr(5) . Chr(6)
VarSetCapacity(ZIPHeader2, 18, 0)
ZIPFile := FileOpen(n, "w")
ZIPFile.Write(ZIPHeader1)
ZIPFile.RawWrite(ZIPHeader2, 18)
ZIPFile.close()
}
;; --------- FUNCTION END ------------------------------------
;출처: https://autohotkey.com/board/topic/60706-native-zip-and-unzip-xpvista7-ahk-l/page-2
;윈도우 10 64비트 환경에서 실행해서 테스트 완료.
'오토핫키' 카테고리의 다른 글
[오토핫키] 텔레그램(Telegram) 봇 API로 나에게 메시지 보내기. (0) | 2020.11.17 |
---|---|
[오토핫키] 메인보드 시리얼 추출 (3) | 2020.01.29 |
[오토핫키] 픽셀 값 DB처럼 저장하기 (0) | 2019.03.26 |
[오토핫키] 네이버 요일 웹툰 제목과 매칭되는 클래스ID 파싱 (0) | 2019.02.27 |
[오토핫키] 한글 OCR (0) | 2019.02.08 |