You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.5 KiB
Plaintext
79 lines
2.5 KiB
Plaintext
|
|
; 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 = D:\Projects\AHK\_Temp\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
|
|
; zipfilepath := A_ScriptDir . "\Test.zip" ;Zip file to be created
|
|
; unzipDirectory := A_ScriptDir . "\ext\" ;Directory to unzip files
|
|
|
|
; Zip(FilesToZip,zipfilepath)
|
|
; Sleep, 500
|
|
; path1 = C:\Users\%A_Username%\Syncthing\Git\Freedomain-Video-Uploader\Lib\Downloads\chrome-win64.zip
|
|
; path2 = C:\Users\%A_Username%\Syncthing\Git\Freedomain-Social-Media-Poster\Lib\chrome-win64
|
|
; Unzip(path1, path2)
|
|
;; --------- END EXAMPLE -------------------------------------
|
|
|
|
|
|
|
|
;; ----------- THE FUNCTIONS -------------------------------------
|
|
Zip(FilesToZip,zipfilepath)
|
|
{
|
|
If Not FileExist(zipfilepath)
|
|
CreateZipFile(zipfilepath)
|
|
psh := ComObjCreate( "Shell.Application" )
|
|
pzip := psh.Namespace( zipfilepath )
|
|
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(zipfilepath)
|
|
{
|
|
Header1 := "PK" . Chr(5) . Chr(6)
|
|
VarSetCapacity(Header2, 18, 0)
|
|
file := FileOpen(zipfilepath,"w")
|
|
file.Write(Header1)
|
|
file.RawWrite(Header2,18)
|
|
file.close()
|
|
}
|
|
|
|
Unzip(zipfilepath, unzipDirectory)
|
|
{
|
|
fso := ComObjCreate("Scripting.FileSystemObject")
|
|
If Not fso.FolderExists(unzipDirectory) ;http://www.autohotkey.com/forum/viewtopic.php?p=402574
|
|
fso.CreateFolder(unzipDirectory)
|
|
psh := ComObjCreate("Shell.Application")
|
|
zippedItems := psh.Namespace( zipfilepath ).items().count
|
|
psh.Namespace( unzipDirectory ).CopyHere( psh.Namespace( zipfilepath ).items, 4|16 )
|
|
Loop {
|
|
sleep 50
|
|
unzippedItems := psh.Namespace( unzipDirectory ).items().count
|
|
ToolTip Unzipping in progress..
|
|
IfEqual,zippedItems,%unzippedItems%
|
|
break
|
|
}
|
|
ToolTip
|
|
}
|
|
;; ----------- END FUNCTIONS ------------------------------------- |