eltorro Posted November 7, 2005 Posted November 7, 2005 (edited) Until there is a plugin we can use this COM dll.expandcollapse popup;zip functions using x-zip.dll ;Get the dll here ;http://xstandard.com/printer-friendly.asp?id=C9891D8A-5390-44ED-BC60-2267ED6763A7 ;quick and dirty example of zip functionality in autoit. dim $oMyError ; Initialize SvenP 's error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ;Show version as proof object created. $objZip = ObjCreate("XStandard.Zip") MsgBox(0,"Version","Version "&$objZip.Version) $objZip = "" ;Add/Create archive $objZip = objCreate("XStandard.Zip") ; .Pack(Source file, Dest archive) $objZip.Pack ("c:\reportcard1.jpg","C:\Temp\Report.zip") $objZip.Pack ("c:\reportcard.bmp","C:\Temp\Report.zip") $objZip = "" ; get archive contents $message ="" $objZip = ObjCreate("XStandard.Zip") ; .Contents(Zip.file.to.get.contents.of) For $objItem In $objZip.Contents("C:\Temp\archive.zip") $message &= $objItem.Path & $objItem.Name & @CRLF Next MsgBox(0,"Contents",$message) $objZip = "" $objItem = "" ;Extract archive to folder $objZip = ObjCreate("XStandard.Zip") ; .UnPack( Zip file , Destination) $objZip.UnPack ("C:\Temp\archive.zip", "C:\Temp\archive") $objZip = "" ;Extract archive using wildcards $objZip = ObjCreate("XStandard.Zip") ; .UnPack (Zip Archive, Dest "*.Whatever") $objZip.UnPack ("C:\Temp\archive.zip", "C:\Temp\wild", "*.jpg") $objZip = "" Exit ; these functs not tested but should work as written ;Archive with different compression levels $objZip = ObjCreate("XStandard.Zip") ; .Pack (Source file, Dest Archive, Keep path (0=false), compression level) $objZip.Pack ("C:\x-zip.doc", "C:\Temp\archive.zip",0 , 9) $objZip.Pack ("C:\sky.jpg", "C:\Temp\archive.zip", 0, 1) $objZip = "" ;Create with default path $objZip = ObjCreate("XStandard.Zip") $objZip.Pack ("C:\x-zip.doc", "C:\Temp\archive.zip", 1) $objZip.Pack ("C:\sky.jpg", "C:\Temp\archive.zip", 1) $objZip = "" ;Create with custom paths (tested and working) $objZip = ObjCreate("XStandard.Zip") ; .Pack (Source file, Dest Archive, Keep path (1=TRUE), Path or default if left blank) $objZip.Pack ("C:\x-zip.doc", "C:\Temp\archive.zip", 1, "files/word") $objZip.Pack ("C:\sky.jpg", "C:\Temp\archive.zip", 1, "files/images") $objZip = "" ;Create archive using wildcards $objZip = ObjCreate("XStandard.Zip") $objZip.Pack ("C:\*.jpg", "C:\Temp\images.zip") $objZip = "" ;Remove file from archive $objZip = ObjCreate("XStandard.Zip") $objZip.Delete ("sky.jpg", "C:\Temp\images.zip") $objZip = "" ;Move file within archive $objZip = ObjCreate("XStandard.Zip") $objZip.Move ("files/images/sky.jpg", "images/sky.jpg", "C:\Temp\images.zip") $objZip = "" ;Rename file in archive $objZip = ObjCreate("XStandard.Zip") $objZip.Move ("files/images/sky.jpg", "files/images/sky1.jpg", "C:\Temp\images.zip") $objZip = "" Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1); to check for after this function returns EndfuncI tested a few of the fuctions and they seem to work. The examples here are just converted from the .asp examples provided on the dll web page and are given only as proof it works.Enjoy EDITIn case the link is dead, here is the main page http://xstandard.com/default.aspclick on all products, the down a little ways is zip component. Edited January 24, 2006 by eltorro IgImAx 1 Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
Raindancer Posted November 7, 2005 Posted November 7, 2005 Great! Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer
randallc Posted November 7, 2005 Posted November 7, 2005 (edited) Hey,Good news.No one looks afer the newbs, oh well...[PS or ourselves, our time; i request lots more scripts that just work, no effort; "feed a man a fish every day, he doesn't have to fish and he can get a life..."];XStandardZip.au3;zip functions using x-zip.dll#include <Process.au3>;Get the dll here;http://xstandard.com/printer-friendly.asp?id=C9891D8A-5390-44ED-BC60-2267ED6763A7;quick and dirty example of zip functionality in autoit.$command="regsvr32 XZip.dll"_RunDOS($command)dim $oMyError, $message; Initialize SvenP 's error handler$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")$objZip = ObjCreate("XStandard.Zip");Add/Create archive$FilesToZip=FileOpenDialog("Choose to Zip",@ScriptDir,"File (*.*)",4)$ArrFilesToZip=StringSplit($FilesToZip,"|")for $i= 2 to $ArrFilesToZip[0]$objZip.Pack ($ArrFilesToZip[$i],@ScriptDir&"\Zipped Files.zip")NextFor $objItem In $objZip.Contents(@ScriptDir&"\Zipped Files.zip") $message = $message&$objItem.Path & $objItem.Name & @CRLFNextMsgBox(0,"Contents",$message)$objItem = ""$objZip.UnPack (@ScriptDir&"Zipped Files.zip", @ScriptDir&"\archive")$objZip = ""ExitBest, Randall Edited November 7, 2005 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
blitzkrg Posted November 7, 2005 Posted November 7, 2005 Hey,Good news.No one looks afer the newbs, oh well...[PS or ourselves, our time; i request lots more scripts that just work, no effort; "feed a man a fish every day, he doesn't have to fish and he can get a life..."]Best, RandallThis is great.. thanks for the work.would it be possible to do something like this with the internal windows xp zip funciton? Wynonaei 1
eltorro Posted November 7, 2005 Author Posted November 7, 2005 would it be possible to do something like this with the internal windows xp zip funciton?No, the api is not exposed. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
jftuga Posted November 7, 2005 Posted November 7, 2005 Nice script! -John Admin_Popup, show computer info or launch shellRemote Manager, facilitates connecting to RDP / VNCProc_Watch, reprioritize cpu intensive processesUDF: _ini_to_dict, transforms ini file entries into variablesUDF: monitor_resolutions, returns resolutions of multiple monitorsReport Computer Problem, for your IT help deskProfile Fixer, fixes a 'missing' AD user profile
blademonkey Posted November 7, 2005 Posted November 7, 2005 Noobish question: Where is the documentation for objcreate() ? I cannot find anything on it in the help file. Thanks in advance. -Monkey. Wynonaei 1 ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung
leecole Posted November 7, 2005 Posted November 7, 2005 Noobish question:Where is the documentation for objcreate() ?I cannot find anything on it in the help file.Thanks in advance.-Monkey.Use Beta version of AutoIt and Beta Help Talking Clockhttp://www.autoitscript.com/forum/index.php?showtopic=20751Talking Headlineshttp://www.autoitscript.com/forum/index.php?showtopic=20655Sometimes, I sits and thinkssometimes, I just sits
KXM Posted November 8, 2005 Posted November 8, 2005 Here are some UDFs I wrote based on what I saw here. expandcollapse popup; ====================================================================================== ; Zip UDFs based on standared fileOpen()/fileClose() system ; Based on other people's work. ; ; Only the more basic function of XZip are represnted (poorly) ; ; Requires: XZip.dll: ; http://xstandard.com/printer-friendly.asp?id=C9891D8A-5390-44ED-BC60-2267ED6763A7 ; ====================================================================================== #include-once #include <array.au3> #include <file.au3> Global $oXZip_UDFGlobal, $sZipPath_UDFGlobal, $oComError_UDFGlobal, $sDllLoc_UDFGlobal, $iRegDelay_UDFGlobal ; ============================================================================ ; Turned off COM erroring ; I don't think it's needed if the scripter is not directly interacting with ; the object, plus it causes an error with my choosen exit(_ZipClose) method ; ============================================================================ ;$oComError_UDFGlobal = ObjEvent("AutoIt.Error", "__XZip_COM_Error") ;=============================================================================== ; ; Description: :Open ZIP file, and load XZip.dll as a service ; Parameter(s): :Archive path, (Opt)XZip.dll path (default to @ScriptDir), ; (opt)Delay between regsrv, and objcreate (default 150 ms) ; Requirement: :XZip.dll, XZip.au3 ; Return Value(s): :True/False (error #) ; User CallTip: :_ZipOpen(ArchivePath, XZipDllPath, Delay in MS) ; ;=============================================================================== ; Func _ZipOpen($sNewArchivePath, $sDllPath = '', $iDelay = 200) If $sDllPath = '' Then $sDllPath = @ScriptDir & '\XZip.dll' ;some error checking If Not FileExists($sDllPath) Then SetError(1) Return False ElseIf Not IsInt($iDelay) Then SetError(2) Return False EndIf ;set the globals $sZipPath_UDFGlobal = $sNewArchivePath $sDllLoc_UDFGlobal = $sDllPath $iRegDelay_UDFGlobal = $iDelay __DOSStart('regsvr32 /s "' & $sDllLoc_UDFGlobal & '"') Sleep($iRegDelay_UDFGlobal);needs a sec when loaded silent. $oXZip_UDFGlobal = ObjCreate('XStandard.Zip') If IsObj($oXZip_UDFGlobal) Then;make sure it's opened Return True Else SetError(3) Return False EndIf EndFunc ;==>_ZipOpen ;=============================================================================== ; ; Description: :List items in given Zip file ; Parameter(s): :None (see _ZipOpen) ; Requirement: :XZip.dll, XZip.au3 ; Return Value(s): :Array contaning archive contents ; User CallTip: :_ZipContents() ; ;=============================================================================== ; Func _ZipContents();this func needs some more work Local $oItem Local $aRet[1] If Not IsObj($oXZip_UDFGlobal) Then SetError(1) Return False EndIf For $oItem In $oXZip_UDFGlobal.Contents ($sZipPath_UDFGlobal) _ArrayAdd($aRet, $oItem.Path & $oItem.Name) Next $aRet[0] = UBound($aRet) Return $aRet EndFunc ;==>_ZipContents ;=============================================================================== ; ; Description: :Add items to opened Zip file ; Parameter(s): :Array contaning item paths, (opt)Retain dir structure ; Requirement: :XZip.dll, XZip.au3 ; Return Value(s): :True/False (error #) ; User CallTip: :_ZipPack(array of item paths, Bool) ; ;=============================================================================== ; Func _ZipPackGroup(ByRef $aItems, $bKeepPath = True);this func needs some more work If Not IsObj($oXZip_UDFGlobal) Then SetError(1) Return False EndIf Local $x For $x = 0 To UBound($aItems) - 1 If Not FileExists($aItems[$x]) Then SetError(2) SetExtended($aItems[$x]) Return False EndIf $oXZip_UDFGlobal.Pack ($aItems[$x], $sZipPath_UDFGlobal, $bKeepPath) Next Return True EndFunc ;==>_ZipPackGroup ;=============================================================================== ; ; Description: :Add all items in a dir to opened Zip file ; Parameter(s): :String dir path ; Requirement: :XZip.dll, XZip.au3 ; Return Value(s): :True/False (error #) ; User CallTip: :_ZipPackDir(DirPath) ; ;=============================================================================== ; Func _ZipPackDir($sDirPath);this is the one that I needed, so it works well Local $aFiles, $x, $i, $aDirs[1], $sStartDir, $sWorkingDir, $sNewDirPath, $iInsert, $sDirInZip If Not IsObj($oXZip_UDFGlobal) Then SetError(1) Return False ElseIf Not StringInStr(FileGetAttrib($sDirPath), 'D') Then SetError(2) Return False EndIf $sStartDir = $sDirPath $aDirs[0] = $sDirPath $i = 0 ; =========================================================== ; This loop might have some unneeded code, because it took a ; lot of trys to get it right. Also some error more checking, ; optimization and clean couldn't hurt. But it works!;) ; =========================================================== Do $sWorkingDir = $aDirs[$i] & '\' $aFiles = _FileListToArray ($aDirs[$i]) For $x = 1 To UBound($aFiles) - 1 If StringInStr(FileGetAttrib($aFiles[$x]), 'D') Then $sNewDirPath = $sDirPath & '\' & $aFiles[$x] $iInsert = $i + 1 _ArrayInsert($aDirs, $iInsert, $sNewDirPath) Else $sDirInZip = StringReplace($sWorkingDir, $sDirPath, '') $oXZip_UDFGlobal.Pack ($sWorkingDir & $aFiles[$x], $sZipPath_UDFGlobal, 1, $sDirInZip) EndIf Next $i = $i + 1 $aFiles = '' Until UBound($aDirs) = $i Return True EndFunc ;==>_ZipPackDir ;=============================================================================== ; ; Description: :Unpack a zip file ; Parameter(s): :String: Path to extract Zip file to ; Requirement: :XZip.dll, XZip.au3 ; Return Value(s): :True/False (error #) ; User CallTip: :_ZipUnpack(ExtractPath) ; ;=============================================================================== ; Func _ZipUnpack($sDestPath) If Not IsObj($oXZip_UDFGlobal) Then SetError(1) Return False EndIf If Not FileExists($sDestPath) Then DirCreate($sDestPath) $oXZip_UDFGlobal.UnPack ($sZipPath_UDFGlobal, $sDestPath) Return True EndFunc ;==>_ZipUnpack ;=============================================================================== ; ; Description: :Close ZIP file, and unload XZip.dll as a service ; Parameter(s): :None, based on _ZipOpen globals ; Requirement: :XZip.dll, XZip.au3 ; Return Value(s): :True/False (error #) ; User CallTip: :_ZipClose(XZipDllPath, Delay in MS) ; ;=============================================================================== ; Func _ZipClose() ;some error checking If Not FileExists($sDllLoc_UDFGlobal) Then SetError(1) Return False EndIf __DOSStart('regsvr32 /s /u "' & $sDllLoc_UDFGlobal & '"') Sleep($iRegDelay_UDFGlobal);needs a sec when unloaded silently. ; ===================================================== ; This way of checking will cause a COM error ; but I like to confirm that the object's been closed ; ===================================================== $oXZip_UDFGlobal = ObjCreate('XStandard.Zip') If Not IsObj($oXZip_UDFGlobal) Then;make sure it's closed ;reset globals, for next call $sZipPath_UDFGlobal = '' $sDllLoc_UDFGlobal = '' $iRegDelay_UDFGlobal = 0 $oXZip_UDFGlobal = '' Return True Else SetError(2) Return False EndIf EndFunc ;==>_ZipClose ;helper functions Func __XZip_COM_Error() Local $hNumber = Hex($oComError_UDFGlobal.number, 8) ;blantly stolen from SvenP (We'll call it a 'port') MsgBox(0, 'XZip Com Error', 'There was COM Error!' & @CRLF & @CRLF & _ 'description is: ' & @TAB & $oComError_UDFGlobal.description & @CRLF & _ 'windescription:' & @TAB & $oComError_UDFGlobal.windescription & @CRLF & _ 'number is: ' & @TAB & $hNumber & @CRLF & _ 'lastdllerror is: ' & @TAB & $oComError_UDFGlobal.lastdllerror & @CRLF & _ 'scriptline is: ' & @TAB & $oComError_UDFGlobal.scriptline & @CRLF & _ 'source is: ' & @TAB & $oComError_UDFGlobal.source & @CRLF & _ 'helpfile is: ' & @TAB & $oComError_UDFGlobal.helpfile & @CRLF & _ 'helpcontext is: ' & @TAB & $oComError_UDFGlobal.helpcontext _ ) SetError(1) EndFunc ;==>__XZip_COM_Error Func __DOSStart($sStart) Run(@ComSpec & ' /c start ' & $sStart, '', @SW_HIDE) EndFunc ;==>__DOSStart #cs UserCalltips _ZipOpen($sNewArchivePath, $sDllPath = '', $iDelay = 150) _ZipContents() _ZipPackGroup(ByRef $aItems, $bKeepPath = True);this func needs some more work _ZipPackDir(DirPath) _ZipUnpack($sDestPath) _ZipClose($sDllPath = '', $iDelay = 150) #ceXZip_UDFs.zip
erifash Posted November 9, 2005 Posted November 9, 2005 Hah! You beat me to it! Great work. Here is what I have come up with: expandcollapse popup#include-once Func _ZipPack( $sZip, $sFile ) If not FileExists($sZip) or not FileExists($sFile) Then Return 0 Local $oZip = ObjCreate("XStandard.Zip") If not IsObj($oZip) Then Return 0 $oZip.Pack($sFile, $sZip) Return 1 EndFunc Func _ZipUnPack( $sZip, $sFolder = @ScriptDir, $sFiles = "*.*" ) If not FileExists($sZip) or not FileExists($sFolder) Then Return 0 Local $oZip = ObjCreate("XStandard.Zip") If not IsObj($oZip) Then Return 0 $oZip.UnPack($sZip, $sFolder, $sFiles) Return 1 EndFunc Func _ZipVersion() Local $oZip = ObjCreate("XStandard.Zip") If not IsObj($oZip) Then Return 0 Return $oZip.Version EndFunc Func _ZipContents( $sZip ) If not FileExists($sZip) Then SetError(1) Return "" EndIf Local $oZip = ObjCreate("XStandard.Zip") If not IsObj($oZip) Then Return 0 Local $oContents = $oZip.Contents($sZip), $iObjs = OBJs($oContents), $i = 0, $aContents[$iObjs + 1][2] $aContents[0][0] = $iObjs For $o in $oContents $i += 1 $aContents[$i][0] = $o.Path $aContents[$i][1] = $o.Name Next Return $aContents EndFunc Func OBJin( $oObject, $iLevel = 1 ) If not IsObj($oObject) Then SetError(1) Return "" EndIf If $iLevel < 1 Then SetError(2) Return "" EndIf Local $i = 1, $o For $o in $oObject If $i = $iLevel Then Return $o $i += 1 Next SetError(3) Return "" EndFunc Func OBJs( $oObject ) If not IsObj($oObject) Then SetError(1) Return 0 EndIf Local $i = 0, $o For $o in $oObject $i += 1 Next If $i = 0 Then SetError(2) Return $i EndFunc My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
KXM Posted November 9, 2005 Posted November 9, 2005 (edited) I figured some one else might be working on some UDFs for this. Nice work, you did all the functions I didn't bother with. Between both our work, I think just about every option is represented. I know mine need a few small bug fixes, and some cleaning. I'm still having some problems with the loop in _ZipPackDir(). Edited November 9, 2005 by KXM
eltorro Posted November 10, 2005 Author Posted November 10, 2005 I reworked the _ZipPackDir UDF to use COM object too. expandcollapse popup;=============================================================================== ; ; Description: :Add all items in a dir to opened Zip file ; Parameter(s): :String dir path ; Requirement: :XZip.dll, XZip.au3 ; Return Value(s): :True/False (error #) ; User CallTip: :_ZipPackDir(DirPath) ;=============================================================================== ; Func _ZipPackDir($sDirPath);this is the one that I needed, so it works well Local $oFSO,$oFolder If Not IsObj($oXZip_UDFGlobal) Then SetError(1) Return False ElseIf Not StringInStr(FileGetAttrib($sDirPath), 'D') Then SetError(2) Return False EndIf $oFSO = ObjCreate("Scripting.FileSystemObject") If Not IsObj($oFSO) Then SetError(3) Return False EndIf $oFolder = $oFSO.GetFolder($sDirPath) _GetFiles($oFolder) $oFSO = "" if @error then SetError(4) Return False Else Return True EndIf EndFunc ;==>_ZipPackDir ;=============================================================================== ; ; Description: :Gets all files and folders using FileSystemObject and puts them in the open Zip file ; Parameter(s): :String dir path ; Requirement: :XZip.dll, XZip.au3 ; Return Value(s): : ; User CallTip: :_GetFiles(DirPath) ;=============================================================================== ; Func _GetFiles($oBegin_Folder) Local $szDrive, $szDir, $szFName, $szExt for $oFileSpec in $oBegin_Folder.Files;add files from dir $sDirInZip = _PathSplit($oFileSpec.path,$szDrive, $szDir, $szFName, $szExt) $oXZip_UDFGlobal.Pack ($oFileSpec.path,$sZipPath_UDFGlobal, 1,$sDirInZip[2]); element 2 is folder next for $oFolderSpec in $oBegin_Folder.subfolders;drill down _GetFiles($oFolderSpec) next Return EndFunc ;==>_GetFiles seems to work fine. eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
zeroZshadow Posted November 11, 2005 Posted November 11, 2005 great thing man, butta is this also for RAR files?? i need a COM way to TEST RAR files if the password is correct thanks *If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...
webmedic Posted December 8, 2005 Posted December 8, 2005 ok so am I missing something? I was pointed here in another thread talking about 7zip but none of this uses 7-zip only regular zip. So how hard would it be to have this working with 7zip?
KXM Posted December 8, 2005 Posted December 8, 2005 It wouldn't be a question of 'hard'. There is no way to make THESE function calls work with 7-Zip. They are based only on the documation from the xzip web site. As far as working w/ 7-Zip, if it supports in any way activex/com, it's really only a matter of finding out the format of the function calls.
webmedic Posted December 8, 2005 Posted December 8, 2005 doh of course I suppose i was more thinking of possibly using it but I figure it may have to be done with dllstruct.
eltorro Posted December 14, 2005 Author Posted December 14, 2005 If I'm not mistaken, 7zip requires a callback function. The doc says it uses a non-standard COM interface but I have as yet deciphered how to use it. So for now, if i need to use 7zip I use via its command line interface. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now