Jump to content

Easy Zip Compression using Windows XP


mozart90
 Share

Recommended Posts

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 by mozart90
Link to comment
Share on other sites

  • Replies 77
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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)

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 
                
            
        
    
    
        


GaryFrost
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Developers
                
                    
                
            
            
                
                    
                        
                            
                                
                            
                                 7.4k
                            
                                
                            
                        
                        
                    
                
            
            
                

    
    
        
RIP: I don't need your attitude. I have one of my own
    
    

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            
@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 
                
            
        
    
    
        


mozart90
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 95
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                        Author
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            
@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 
                
            
        
    
    
        


randallc
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 1.9k
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            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 
                
            
        
    
    
        


leecole
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 62
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                    (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 Mozart90

This 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 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

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. :lmao:

I'm glad to see someone got it working!

Cheers

Link to comment
Share on other sites

Very nice! I bet you wouldn't mind if I turned this into some functions:

Func _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
EndFunc
Example:
_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! :lmao:

Link to comment
Share on other sites

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.... :lmao:

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.

o:)

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 by mozart90
Link to comment
Share on other sites

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 by JerryD
Link to comment
Share on other sites

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 at

Greetings

Mozart90

Edited by mozart90
Link to comment
Share on other sites

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.

Dim $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

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.
Link to comment
Share on other sites

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...