Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Zip Unzip Easily [COM] [AHK_L]


  • Please log in to reply
2 replies to this topic
shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
Zip/Unzip using a free COM library. Zipping and unzipping take only a couple of lines of code!

I have just wrapped the functions to be compatible with AHK_L COM syntax and modified the documentation to be easier for newbies to understand.
I have tested the example codes, and work great on my machine!

Requires: Autohotkey_L and 32bit OS
Reference -> http://www.xstandard...mentation/xzip/

Overview
Quote - "The Zip component provides industry-standard Zip archive functionality. It is designed to be easy to use. You can pack/unpack a file or folder with a single line of code. If you need to create or extract Zip files on the fly, this component is for you. This component can be used in environments that support COM.."

Installation Instructions
Official Download - Download Zip Component (138 Kb), Mirror
Move the dll to a directory like: "C:\Program Files\XZip\"
Open a command prompt and cd to the directory where the dll is located.
Type regsvr32 XZip.dll
Note: Vista/7, the command prompt must be "Run as administrator".

Uninstall Instructions
Open a command prompt and cd to the directory where the dll is located.
Type regsvr32 -u XZip.dll

Classes, Functions, Methods, Properties
obj.Pack(sFilePath, sArchive, [bStorePath As Boolean = False], [sNewPath], [CompressionLevel = -1])
; Add file or folder to an archive. 
; Compression level 1 is minimum, level 9 is maximum, all other values default to level 6.

obj.UnPack(sArchive, sFolderPath, [sPattern])
; Extract contents of an archive to a folder.

obj.Delete(sFile, sArchive)
; Remove a file from an archive.

obj.Move(sFrom, sTo, sArchive)
; Move or rename a file in the archive.

objContents := obj.Contents(sArchive)
; Get a list of files and folder in the archive.

Class: Items (Read-only)
Items.Count ; Returns the number of members in a collection.
Item := Items.Item(Index) ;Returns a specific member of a collection by position.

Class: Item (Read-only)
Item.Date ;Last modified date.
Item.Name ;File name.
Item.Path ;Relative path.
Item.Size ;File size in bytes.
Item.Type ;Type of object.

Enum: ItemType
tFolder = 1 ;Item is a folder.
tFile = 2 ;Item is a file.

Examples

How to archive (or zip) multiple files
objZip := ComObjCreate("XStandard.Zip")
objZip.Pack("C:\Temp\golf.jpg", "C:\Temp\images.zip")
objZip.Pack("C:\Temp\racing.gif", "C:\Temp\images.zip")

How to archive (or zip) multiple files with different compression levels
objZip := ComObjCreate("XStandard.Zip")
objZip.Pack("C:\Temp\reports.doc", "C:\Temp\archive.zip","" ,"" , 9)
objZip.Pack("C:\Temp\boat.jpg", "C:\Temp\archive.zip","" ,"" , 1)

How to archive (or zip) multiple files with default path
objZip := ComObjCreate("XStandard.Zip")
objZip.Pack("C:\Temp\reports.doc", "C:\Temp\archive.zip", True)
objZip.Pack("C:\Temp\boat.jpg", "C:\Temp\archive.zip", True)

How to archive (or zip) multiple files with a custom path
objZip := ComObjCreate("XStandard.Zip")
objZip.Pack("C:\Temp\reports.doc", "C:\Temp\archive.zip", True, "files/word")
objZip.Pack("C:\Temp\boat.jpg", "C:\Temp\archive.zip", True, "files/images")

How to archive (or zip) multiple files using wildcards
objZip := ComObjCreate("XStandard.Zip")
objZip.Pack("C:\Temp\*.jpg", "C:\Temp\images.zip")

How to unzip files
objZip := ComObjCreate("XStandard.Zip")
objZip.UnPack("C:\Temp\images.zip", "C:\Temp\")

How to unzip files using wildcards
objZip := ComObjCreate("XStandard.Zip")
objZip.UnPack("C:\Temp\images.zip", "C:\Temp\", "*.jpg")

How to get a listing of files and folder in an archive
objZip := ComObjCreate("XStandard.Zip")
objContents := objZip.Contents(A_ScriptDir . "\test.zip")._NewEnum
While objContents[objItem]
	Msgbox % objItem.Path . objItem.Name . "`n"

How to remove a file from an archive
objZip := ComObjCreate("XStandard.Zip")
objZip.Delete("headshots/smith.jpg", "C:\Temp\images.zip")

How to move a file in an archive
objZip := ComObjCreate("XStandard.Zip")
objZip.Move("headshots/jones.jpg", "staff/jones.jpg", "C:\Temp\images.zip")

How to rename a file in an archive
objZip := ComObjCreate("XStandard.Zip")
objZip.Move("headshots/jones.jpg", "headshots/randy-jones.jpg", "C:\Temp\images.zip")

Known Issues
The UnPack() method will first remove all files from the destination folder. This behavior will change in future releases.
This component was not designed to work with huge archives. Max archive size depends on the amount of available RAM.
This component is designed for 32-bit operating systems and will not work natively on 64-bit operating systems.

Error codes
200 Archive file is not correct.
201 Archive file is not a valid zip file[header].
202 Archive file is not a valid zip file[dir].
203 Cannot create archive file.
204 Compressed header is not correct
205 File size is not correct.
206 Cannot Alloc memory
207 Cannot open archive file
208 Archive file is empty
209 Cannot alloc memeory.
210 Cannot find source file.
211 Cannot open file
212 Cannot alloc memory.
213 Cannot alloc memory.
214 There is no file.
215 Archive file is same as the input file.
216 Cannot Alloc memory.
217 Incorrect signature of header
230 Cannot open archive file.
240 Archive file is not correct.
241 Archive file is not a valid zip file[header].
242 Archive file is not a valid zip file[dir].
250 Cannot open archive file.
251 Archive file is not correct.
252 Cannot create file for swapping.
253 Header of archive file is incorrect.
254 Unknown error when modifying archive file.
290 Cannot get information from archive file.
291 Cannot get information from archive file.
591 Cannot get information from archive file.

side
  • Members
  • 168 posts
  • Last active: Nov 30 2014 03:41 PM
  • Joined: 01 Nov 2012
#LTrim on
#SingleInstance,Force

;===Version Check===
if (A_Is64bitOS = 1 || A_AhkVersion < 1.1.09.04 )
{
MsgBox,Xzip requires AutoHotkey_L and 32bit OS
exitapp
}
;===End===


ifnotexist,%A_ProgramFiles%\Xzip\Xzip.dll
{
Gui,Add,Text,,Welcome `n
Gui, Add,Text,w200, Please choose an action
Gui,Add,Button,w100,Install
Gui,Add,Button,w100,Exit
Gui, Add, Text,w200,`n
Gui,Add,Button,Default w100,Error List
Gui,Show
return
}

Ifexist,%A_ProgramFiles%\Xzip\Xzip.dll
{
Gui,Add,Text,,Welcome
Gui, Add, Text,w200, Please choose an action
Gui,Add,Button,w100,Uninstall
Gui,Add,Button,w100,Exit
Gui, Add, Text,w200,`n
Gui,Add,Text,,Xzip.dll is now located at:
Gui,Add,Edit,ReadOnly,%A_ProgramFiles%\Xzip
Gui, Add, Text,w200,`n
Gui,Add,Button,Default w100,Error List
Gui,Show
return
}

;=========Buttons==========
ButtonInstall:
if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"      
}

ifexist,%A_ProgramFiles%\Xzip\
{
MsgBox,4,,Xzip Directory already exists.`nPress YES to overwrite or NO to exit installer
ifmsgbox NO
    exitapp
else    
    goto,Label
}

Label:
FileRemoveDir,%A_ProgramFiles%\Xzip,1
FileCreateDir,%A_ProgramFiles%\Xzip\
;FileMove,%A_ScriptDir%\xzip.dll,%A_ProgramFiles%\Xzip\
FileCopy,%A_ScriptDir%\xzip.dll,%A_ProgramFiles%\Xzip\
FileAppend,cd \Program Files\Xzip`nregsvr32 XZip.dll,%A_ScriptDir%\TEMP.cmd
Run %A_ScriptDir%\TEMP.cmd
MsgBox,XZip installed and registered successfully!
FileDelete,%A_ScriptDir%\TEMP.cmd
exitapp

ButtonUninstall:
if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"      
}
FileAppend,cd \Program Files\Xzip`nregsvr32 -u XZip.dll,%A_ScriptDir%\TEMP1.cmd
Run %A_ScriptDir%\TEMP1.cmd
Msgbox,XZip uninstalled and unregistered succefully!
FileDelete,%A_ScriptDir%\TEMP1.cmd
FileRemoveDir,%A_ProgramFiles%\Xzip\,1
exitapp

ButtonHelp:
msgbox,
(LTrim
200 Archive file is not correct
201 Archive file is not a valid zip file[header].
202 Archive file is not a valid zip file[dir].
203 Cannot create archive file.
204 Compressed header is not correct
205 File size is not correct.
206 Cannot Alloc memory
207 Cannot open archive file
208 Archive file is empty
209 Cannot alloc memeory.
210 Cannot find source file.
211 Cannot open file
212 Cannot alloc memory.
213 Cannot alloc memory.
214 There is no file.
215 Archive file is same as the input file.
216 Cannot Alloc memory.
217 Incorrect signature of header
230 Cannot open archive file.
240 Archive file is not correct.
241 Archive file is not a valid zip file[header].
242 Archive file is not a valid zip file[dir].
250 Cannot open archive file.
251 Archive file is not correct.
252 Cannot create file for swapping.
253 Header of archive file is incorrect.
254 Unknown error when modifying archive file.
290 Cannot get information from archive file.
291 Cannot get information from archive file.
591 Cannot get information from archive file.
)
return

ButtonExit:
GuiClose:
exitapp



 


Here is MY automated installer happy.png
please tell me your thoughts
(Keep .dll in %A_ScriptDir% happy.png )



over21
  • Members
  • 33 posts
  • Last active: Jul 30 2014 01:45 PM
  • Joined: 09 Mar 2010

Got it working :) Many thanks!