[오토핫키] 압축 및 압축해제 / Zip to File , File to Zip

2019. 7. 22. 17:26·오토핫키·
#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
'오토핫키' 카테고리의 다른 글
  • [오토핫키] 텔레그램(Telegram) 봇 API로 나에게 메시지 보내기.
  • [오토핫키] 메인보드 시리얼 추출
  • [오토핫키] 픽셀 값 DB처럼 저장하기
  • [오토핫키] 네이버 요일 웹툰 제목과 매칭되는 클래스ID 파싱
징쟝
징쟝
IT 관련 네트워크 및 기타 자료들을 수집하고 공유하는데 목적이 있음.
  • 징쟝
    네트워커의 보안 티스토리
    징쟝
  • 전체
    오늘
    어제
  • 블로그 메뉴

    • 홈
    • 글쓰기
    • 관리
    • 방명록
    • 분류 전체보기 (151)
      • 정보보안 (54)
      • 리눅스 (10)
      • Windows (6)
      • Cisco (2)
      • Mikrotik (0)
      • Cyberoam (0)
      • Juniper (6)
      • MRTG (0)
      • Sophos (3)
      • SecuWiz (0)
      • Forti (0)
      • SECUI (1)
      • L4 (3)
      • 파이오링크 (0)
      • 오토핫키 (43)
      • 파이썬 (0)
      • 직장 (0)
      • 개인적인 것들 (9)
      • 그 외의 것들 (9)
      • 영화 (0)
      • 테스트 (1)
      • 일기장 (0)
      • 쓰레기통 (3)
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    HTML
    웹해킹
    해킹
    오토핫키
    MySQL
    웹보안
    SQL
    spoofing
    정보보안
    CSRF
    NAT
    인젝션
    php
    보안
    web
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
징쟝
[오토핫키] 압축 및 압축해제 / Zip to File , File to Zip
상단으로

티스토리툴바