I used code from https://www.autohotkey.com/board/topic/60706-native-zip-and-unzip-xpvista7-ahk-l/
Here is my "code"
Code: Select all
/* ,---, ,--,
,--.' | ,--.'|
| | : .--. ,--, | | :
.--.--. : : : .--,`| ,'_ /| : : '
/ / ' : | |,--. ,--.--. | |. .--. | | : | ' |
| : /`./ | : ' | / \ '--`_ ,'_ /| : . | ' | |
| : ;_ | | /' :.--. .-. | ,--,'|| ' | | . . | | :
\ \ `.' : | | | \__\/: . . | | '| | ' | | | ' : |__
`----. \ | ' | : ," .--.; | : | |: | : ; ; | | | '.'|
/ /`--' / : :_:,'/ / ,. | __| : '' : `--' \; : ;
'--'. /| | ,' ; : .' \.'__/\_: |: , .-./| , /
`--'---' `--'' | , .-./| : : `--`----' ---`-'
`--`---' \ \ /
`--`-'
Zip/Unzip file(s)/folder(s)/wildcard pattern files
Requires: Autohotkey_L, Windows > XP
URL: http://www.autohotkey.com/forum/viewtopic.php?t=65401
Credits: Sean for original idea
*/
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;; --------- EXAMPLE CODE -------------------------------------
; FilesToZip = C:\Users\V1t3r\Desktop\Hell Backkup\test ;Example of folder to compress
; FilesToZip = D:\Projects\AHK\_Temp\Test\*.ahk ;Example of wildcards to compress
; FilesToZip := A_ScriptFullPath ;Example of file to compress
sZip := A_ScriptDir . "\Test.zip" ;Zip file to be created
sUnz := A_ScriptDir . "\ext\" ;Directory to unzip files
;
;Sleep, 500
;Unz(sZip,sUnz)
;; --------- END EXAMPLE -------------------------------------
;; ----------- THE FUNCTIONS -------------------------------------
Zip(FilesToZip,sZip)
{
If Not FileExist(sZip)
CreateZipFile(sZip)
psh := ComObjCreate( "Shell.Application" )
pzip := psh.Namespace( sZip )
if InStr(FileExist(FilesToZip), "D")
FilesToZip .= SubStr(FilesToZip,0)="\" ? "*.*" : "\*.*"
loop,%FilesToZip%,1
{
zipped++
ToolTip Zipping %A_LoopFileName% ..
pzip.CopyHere( A_LoopFileLongPath, 4|16 )
Loop
{
done := pzip.items().count
if done = %zipped%
break
}
done := -1
}
ToolTip
}
CreateZipFile(sZip)
{
Header1 := "PK" . Chr(5) . Chr(6)
VarSetCapacity(Header2, 18, 0)
file := FileOpen(sZip,"w")
file.Write(Header1)
file.RawWrite(Header2,18)
file.close()
}
Unz(sZip, sUnz)
{
fso := ComObjCreate("Scripting.FileSystemObject")
If Not fso.FolderExists(sUnz) ;http://www.autohotkey.com/forum/viewtopic.php?p=402574
fso.CreateFolder(sUnz)
psh := ComObjCreate("Shell.Application")
zippedItems := psh.Namespace( sZip ).items().count
psh.Namespace( sUnz ).CopyHere( psh.Namespace( sZip ).items, 4|16 )
Loop {
sleep 50
unzippedItems := psh.Namespace( sUnz ).items().count
ToolTip Unzipping in progress..
IfEqual,zippedItems,%unzippedItems%
break
}
ToolTip
}
;; ----------- END FUNCTIONS -------------------------------------
;--------- GUI ----------
Gui, Add, Tab3,w330 h85,Zip Files|Folder Zip|Folder Unzip
Gui, Tab, Folder Zip
Gui, Add, Edit,r1 vFolderToZip w200, %FolderToZip%
Gui, Add , Button,x230 y33 w102, FolderSelect
Gui, Add , Button,x21 y60 w312, ZipIt
Gui, Tab, Zip Files
Gui, Add, Edit,r1 v1FilesToZip w200, %1FilesToZip%
Gui, Add , Button,x230 y33 w102, FilesSelect
Gui, Add , Button,x21 y60 w312, ZipItFile
Gui, Tab, Folder Unzip
Gui, Add, Edit,r1 vFileToUnzip w200, %FileToUnzip%
Gui, Add, Edit,r1 vWhereToUnzip w200, %WhereToUnzip%
Gui, Add , Button, x230 y33, SelectZip
Gui, Add , Button, x290 y33, UnzipIt
Gui, Add , Button, x230 y60 w102, ExtractFolder
Gui, Show
Return
ButtonFilesSelect:
FileSelectFile, 1FilesToZip, M3
GuiControl,, 1FilesToZip, %1FilesToZip%
Return
ButtonZipItFile:
Zip(1FilesToZip,sZip)
Return
ButtonFolderSelect:
FileSelectFolder, FolderToZip
GuiControl,, FolderToZip, %FolderToZip%
Return
ButtonZipIt:
Zip(FolderToZip,sZip)
;Zip(FilesToZip,sZip)
MsgBox, Done
Return
ButtonSelectZip:
FileSelectFile, FileToUnzip, , ,Select Zip,Zip Files (*.zip)
GuiControl,,FileToUnzip, %FileToUnzip%
Return
ButtonExtractFolder:
FileSelectFolder, WhereToUnzip
GuiControl,,WhereToUnzip, %WhereToUnzip%
Return
ButtonUnzipIt:
Unz(FileToUnzip,WhereToUnzip)
MsgBox, Done
Return