mozart90 Posted January 31, 2006 Share Posted January 31, 2006 (edited) Hi,searching for an easy method to create a Zip archive without any external stuff I had the following idea:Using the zip file as an folder ... and thats the way I did it...This is only tested with Windows XP and you need a Beta Version of Autoit.Perhaps it works with Win2000 or Win98(plus package)Read here. Thanks eltorro.The Idea:$ZipArchive = "c:\temp\tmp.zip"; Put here the full path and name ame of archive you would like to create $AddFile = "c:\autoexec.bat"; Put here the the File you would like to compress in the zip $AddFile2 = "c:\config.sys"; Take another File ... $oShell = ObjCreate("Shell.Application"); Create s shell Object if IsObj($oShell) then InitZip($ZipArchive); Create an emtpy zip file with header $oDir = $oShell.NameSpace($ZipArchive); Use the zip file as an "Folder" $oDir.CopyHere ($AddFile); Copy a file in the "Zip Folder" $oDir.CopyHere ($AddFile2); Copy a second file sleep (500); Give the Objekt a litte bit time to work else Msgbox (0,"Error","Error creating Object.") endif Func InitZip ($zip_path_name) $init_zipString= Chr(80) & Chr(75) & Chr(5) & Chr(6);Create the Header String for $n =1 to 18;the $init_zipString= $init_zipString & Chr(0);Header next $file =FileOpen($zip_path_name,2) FileWrite($file,$init_zipString);Write the string in a file FileClose($file) EndFunc oÝ÷ Ù8b³¬¶jÈסøhÂ+¢é]ÂäN®º+©Ý)àË-YfË"§¶¬{¦¦Wh¶Wë¢cìj[r /ÛbjwâÖ¤wh}@ź¹Perhaps you have to change the title string from winexists. I do not know what is displayed in an english XP version. Greetings Mozart90 Edited August 9, 2006 by mozart90 Easy Zip Compression using XP Link to comment Share on other sites More sharing options...
tonedeaf Posted January 31, 2006 Share Posted January 31, 2006 @mozart90 and to think it was presumed that WinXP ZIP API was not exposed. Excellent! Link to comment Share on other sites More sharing options...
flaxcrack Posted January 31, 2006 Share Posted January 31, 2006 Hi, searching for an easy method to create a Zip archiv without any external stuff I had the following idea: Using the zip file as an folder ... and thats the way I did it... (This works only with Windows XP and you need a Beta Version of Autoit) expandcollapse popup if IsObj($oShell) then InitZip($ZipAchive) ; Create an emtpy zip file with header $oDir = $oShell.NameSpace($ZipAchive); Use the zip file as an "Folder" $oDir.CopyHere ($AddFile) ; Copy a file in the "Zip Folder" $oDir.CopyHere ($AddFile2) ; Copy a second file sleep (500) ; Give the Objekt a litte bit time to work else @Mozart90 is some of this VB? If so are you using AutoITX? Can you please explain? [quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD() Link to comment Share on other sites More sharing options... GaryFrost Posted January 31, 2006 GaryFrost Developers 7.4k RIP: I don't need your attitude. I have one of my own Share Posted January 31, 2006 @Mozart90 is some of this VB? If so are you using AutoITX? Can you please explain? Using the beta version which has obj/com SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options... mozart90 Posted January 31, 2006 mozart90 Active Members 95 Author Share Posted January 31, 2006 @Mozart90 is some of this VB? If so are you using AutoITX? Can you please explain? Hi,no, this isn't VB! It's pure Autoit :-)But you have to compile this with the beta version of Autoit because it uses objects, and objects arenot supported in autoit (3.1.1?). You find this Version on the downloadpage of Autoit (scroll down and there is the beta dl link..)Hope that helps...Greetings Mozatz90 Easy Zip Compression using XP Link to comment Share on other sites More sharing options... randallc Posted February 1, 2006 randallc Active Members 1.9k Share Posted February 1, 2006 Hi, I haven't tried it yet, but good to know.. There were probs with the other zipper which used obj, I understand, but that was not Windows zipper. Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options... leecole Posted February 1, 2006 leecole Active Members 62 Share Posted February 1, 2006 (edited) Hi, searching for an easy method to create a Zip archiv without any external stuff I had the following idea: Using the zip file as an folder ... and thats the way I did it... (This works only with Windows XP and you need a Beta Version of Autoit) $ZipAchive = "c:\temp\tmp.zip"; Put here the full path and name ame of archive you would like to create $AddFile = "c:\autoexec.bat"; Put here the the File you would like to compress in the zip $AddFile2 = "c:\config.sys"; Take another File ... $oShell = ObjCreate("Shell.Application"); Create s shell Object if IsObj($oShell) then InitZip($ZipAchive) ; Create an emtpy zip file with header $oDir = $oShell.NameSpace($ZipAchive); Use the zip file as an "Folder" $oDir.CopyHere ($AddFile); Copy a file in the "Zip Folder" $oDir.CopyHere ($AddFile2); Copy a second file sleep (500) ; Give the Objekt a litte bit time to work else Msgbox (0,"Error","Error creating Object.") endif Func InitZip ($zip_path_name) $init_zipString= Chr(80) & Chr(75) & Chr(5) & Chr(6);Create the Header String for $n =1 to 18 ;the $init_zipString= $init_zipString & Chr(0);Header next $file =FileOpen($zip_path_name,2) FileWrite($file,$init_zipString) ;Write the string in a file FileClose($file) EndFunc This is only the basic idea of how it could work . The error handling is still missing. Perhaps you have some good ideas. Feel free to improve the method. Greetings Mozart90This is Great! Thanks, here is what I did. Compile and execute it once. It will place a Shortcut on your DeskTop. Then bring up explorer, select Folders or a group of files, then DRAG/DROP onto the XP_Zip desktop shortcut. XP_Zip will then select the "common" path from all the folders or files selectd, then prompt for a Archive name. It will then build a ZIP file of all folders or files selected at the "common" path with your "Archive" name with file extension of ZIP. #include <File.au3> Dim $ZipAchive Dim $AddFile Dim $drive,$dir,$Fname,$Ext ; Self install If Not FileExists(@DesktopDir & "\XP_Zip.lnk") Then FileCreateShortcut (@ScriptDir & "\XP_Zip.exe", @DesktopDir & "\XP_Zip.lnk") ; Determine the lest common path and use that as ARCHIVE path If $CmdLine[0] = 0 Then Exit For $i = 1 to $CmdLine[0] _PathSplit($CmdLine[$i], $drive,$dir,$Fname,$Ext) If Not StringInStr($ZipAchive,$drive & $dir) Then $ZipAchive = $drive & $dir Next ; Prompt for Archive name $ZipAchive = $ZipAchive & InputBox("XP Zip","Enter Archize Name","Archive") & ".zip" ; Create the Zip $oShell = ObjCreate("Shell.Application"); Create s shell Object if IsObj($oShell) then InitZip($ZipAchive) ; Create an emtpy zip file with header $oDir = $oShell.NameSpace($ZipAchive); Use the zip file as an "Folder" For $i = 1 to $CmdLine[0] $oDir.CopyHere ($CmdLine[$i]) ; Copy a file in the "Zip Folder" Next ; $oDir.CopyHere ($AddFile2) ; Copy a second file sleep (500) ; Give the Objekt a litte bit time to work else Msgbox (0,"Error","Error creating Object.") endif Edited February 1, 2006 by leecole 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 Link to comment Share on other sites More sharing options...
eltorro Posted February 1, 2006 Share Posted February 1, 2006 Ya now, that pretty cool. Create an empty zip file, and then add files to it. I think I tried this before and I must have screwed the header because it didn't work then. I'm glad to see someone got it working! Cheers 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 Link to comment Share on other sites More sharing options...
masvil Posted February 1, 2006 Share Posted February 1, 2006 searching for an easy method to create a Zip archiv without any external stuff I had the following idea:Impressive Congratulation! Link to comment Share on other sites More sharing options...
erifash Posted February 2, 2006 Share Posted February 2, 2006 Very nice! I bet you wouldn't mind if I turned this into some functions: expandcollapse popupFunc _ZipCreate( $sZip ) If not StringLen(Chr(0)) Then Return SetError(1) Local $sHeader = Chr(80) & Chr(75) & Chr(5) & Chr(6), $hFile For $i = 1 to 18 $sHeader &= Chr(0) Next $hFile = FileOpen($sZip, 2) FileWrite($hFile, $sHeader) FileClose($hFile) EndFunc Func _ZipAdd( $sZip, $sFile ) If not StringLen(Chr(0)) Then Return SetError(1) If not FileExists($sZip) or not FileExists($sFile) Then Return SetError(2) Local $oShell = ObjCreate('Shell.Application') If @error or not IsObj($oShell) Then Return SetError(3) Local $oFolder = $oShell.NameSpace($sZip) If @error or not IsObj($oFolder) Then Return SetError(4) $oFolder.CopyHere($sFile) Sleep(500) EndFunc Func _ZipList( $sZip ) If not StringLen(Chr(0)) Then Return SetError(1) If not FileExists($sZip) Then Return SetError(2) Local $oShell = ObjCreate('Shell.Application') If @error or not IsObj($oShell) Then Return SetError(3) Local $oFolder = $oShell.NameSpace($sZip) If @error or not IsObj($oFolder) Then Return SetError(4) Local $oItems = $oFolder.Items() If @error or not IsObj($oItems) Then Return SetError(5) Local $i = 0 For $o in $oItems $i += 1 Next Local $aNames[$i + 1] $aNames[0] = $i $i = 0 For $o in $oItems $i += 1 $aNames[$i] = $oFolder.GetDetailsOf($o, 0) Next Return $aNames EndFuncExample:_ZipCreate(@ScriptDir & "\test.zip") _ZipAdd(@ScriptDir & "\test.zip", @ScriptFullPath) $list = _ZipList(@ScriptDir & "\test.zip") For $i = 0 to UBound($list, 1) - 1 MsgBox(0, '[' & $i & ']', $list[$i]) Next I also added a function that will get all filenames out of the zip archive. Awesome work though! 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 Link to comment Share on other sites More sharing options...
mozart90 Posted February 3, 2006 Author Share Posted February 3, 2006 (edited) Very nice! I bet you wouldn't mind if I turned this into some functions: nice work! erifash Some annotations for folder support in the zip: For those who want to use folders in the created zip file - the shell.application object crashes while trying to create a new folder in the zip. The Scripting.FileSystemObject shows this behaviour as well. For those who want to have a second try: ;(assumend you have an empty tmp.zip file in c:\temp) $oShell= ObjCreate("Shell.Application") $oDir = $oShell.NameSpace(c:\temp\tmp.zip) $objFolder.NewFolder("blub") ;(assumend you have an empty tmp.zip file in c:\temp) $oFSO = ObjCreate("Scripting.FileSystemObject") $odir=$oFSO.CreateFolder("c:\temp\tmp.zip\blub") Both Methods end with an error.... But with the 'CopyHere' or 'MoveHere' method it's no problem to copy whole folders in the zip. Just give the copy method a folder instead of a file. So you can build up your desired structure on the harddisk and finally move/ copy it to the zip file. Example: $oDir.CopyHere (c:\temp); create a folder 'temp' in the zip and copy all files from c:\temp\*.* to the zip folder \temp . or $oDir.MoveHere (c:\temp); the same but delete the stuff after copying Have a nice day Mozart90 Edited February 3, 2006 by mozart90 Easy Zip Compression using XP Link to comment Share on other sites More sharing options...
JerryD Posted February 3, 2006 Share Posted February 3, 2006 (edited) Fantastic! (???) Just a quick question. What's this for? If Not StringLen(Chr(0)) OK, wait a sec. I tried all the code here, and none of it is working for me. Yes, I'm running beta - 106. It's failing on the NameSpace calls - it seems because NameSpace doesn't like getting a file as a paramater. In fact, my _GetFileSize UDF (see sig) uses the same thing, but when it calls NameSpace, it passes a directory name with a trailing backslash (yep tried that too). I even fired up a clean XP SP2 VMWare box to make sure it wasn't WinZip that was causing the problem, but got the same results (AutoIt and stuff for it are the only things installed). Sup with that???? Edited February 3, 2006 by JerryD Link to comment Share on other sites More sharing options...
flaxcrack Posted February 3, 2006 Share Posted February 3, 2006 Using the beta version which has obj/comIs there a manual on how to use this stuff? I would love to learn. [quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD() Link to comment Share on other sites More sharing options...
flaxcrack Posted February 3, 2006 Share Posted February 3, 2006 Is there a manual on how to use this stuff? I would love to learn.Nevermind! I should of looked before I asked. Thanks! [quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD() Link to comment Share on other sites More sharing options...
mozart90 Posted February 3, 2006 Author Share Posted February 3, 2006 (edited) Fantastic! (???)I even fired up a clean XP SP2 VMWare box to make sure it wasn't WinZip that was causing the problem, but got the same results (AutoIt and stuff for it are the only things installed).Hm I have tried this with several XP versions ... and it always works on XP SP2.Have you tried to copy manually a file in the empty zip archive? This must work because otherwise it 's useless to automate this process.... There are some registry tweaks that disable the internal zip handling. Perhaps you may have a look atGreetings Mozart90 Edited February 3, 2006 by mozart90 Easy Zip Compression using XP Link to comment Share on other sites More sharing options...
sinvos Posted February 4, 2006 Share Posted February 4, 2006 First off good job i was aware about this in .net but i would of never of thought to put in autoit cause i couldnt think it could be done by creating the dummy.zip without doing a byte array. So thank you showing me how to create the dummy file. The script i made uses more shell objects to create browsers to search for the files and folder as seen below i documented best i can put the microsoft links for the objects am using. Only reason i wrote this was show a different way of doing what you did. Basically you got a choice either enter path by using a Input box hit cancel then a browser will pop and you can pick your zip if you want to create one then you will enter the inputbox the path and name of the zip then it will create it. expandcollapse popupDim $Shell,$srcFolder,$DestFolder,$items;Objects Const $BIF_BROWSEINCLUDEFILES = 0x4000 Const $ssfPERSONAL = 0x5;My Documents directory $Shell = ObjCreate("Shell.Application") ;$Destfolder = "C:\Backups\tmp.zmp" ;will copy the directory myscripts and everything in it ;if you do c:\myscripts\ then it just copies the directory contents and not myscripts directory ;$srcFolder = "C:\myscripts" $answer = InputBox("Create zip File",'Enter Name of file and path (example."c:\myzip.zip") otherwise hit cancel to browse for zip',"") If @error = 1 then $DestFolder = $shell.browseforfolder(0,"Pick Destination Folder or Zip",$BIF_BROWSEINCLUDEFILES) Else initzip($answer) $Destfolder = $answer EndIF ;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/objects/shell/browseforfolder.asp ;also you can define a default path for the brosweforfolder to open as fourth parameter as so below example ;$DestFolder = $shell.browseforfolder(0,"Pick Destination Folder or Zip",$BIF_BROWSEINCLUDEFILES,$ssfPERSONAL) $srcFolder = $shell.browseforfolder(0,"Pick Source Folder or File",$BIF_BROWSEINCLUDEFILES) ;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/objects/folder/copyhere.asp $Shell.NameSpace($DestFolder).Copyhere ($srcFolder,0) ; DO NOT REMOVE IT NEEDS IT BECAUSE WHEN TRYING TO MOVE FILES TO A ZIP IT CREATES _ ;A NEW PROCESS IF SCRIPTS FINISHES BEFORE COPING STARTS YOU GET A EMPTY ZIP FILE!!!! sleep(5000) Func InitZip ($zip_path_name) If NOT FileExists($zip_Path_name) then $init_zipString= Chr(80) & Chr(75) & Chr(5) & Chr(6);Create the Header String for $n =1 to 18 ;the $init_zipString= $init_zipString & Chr(0);Header next $file =FileOpen($zip_path_name,2) FileWrite($file,$init_zipString) ;Write the string in a file FileClose($file) EndIf EndFunc It just a quick way of creating a zip then adding content to it and i didnt want to waste alot of time creating gui interface for doing the browser so i used was already availably to me not alot of people are aware of browser so this was a perfect example hopefully people can find a use for it. Once again thanks for sharing your findings. Link to comment Share on other sites More sharing options...
erifash Posted February 6, 2006 Share Posted February 6, 2006 Just a quick question. What's this for? If Not StringLen(Chr(0))It is used to check the version of AutoIt you have. Since it needs to handle character 0 in the for...next loop it needs to be higher than 3.1.1.76 (I think) because that was when binary support was added. 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 Link to comment Share on other sites More sharing options...
masvil Posted February 17, 2006 Share Posted February 17, 2006 (edited) Func _ZipAdd( $sZip, $sFile )Is there a way to hide the compression progress window? Edited February 17, 2006 by masvil Link to comment Share on other sites More sharing options...
erifash Posted February 18, 2006 Share Posted February 18, 2006 As far as I have tried... nope, sorry. 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 Link to comment Share on other sites More sharing options...
masvil Posted February 18, 2006 Share Posted February 18, 2006 As far as I have tried... nope, sorry. It seems to appear for big size file adding Anyway... thanx for effort. Link to comment Share on other sites More sharing options...
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