Jump to content
Sign in to follow this  
NDTC

Unable to include chr(0) in string necessary to build an empty ZIP file.

Recommended Posts

NDTC

Hi,

I found on this forum a topic who can create an Easy Zip Compression using Windows XP buid by Mozart90.

Her the code:

$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

I use the last version of AutoIT (v3.2.10.0).

but the $init_zipString= $init_zipString & Chr(0) not work.

See this Hexa editor screenshot attached to view this the file: post-35156-1209571292_thumb.jpg

The second file is an empty ZIP file created by WinXP.

Can you help me please?

If anyone have a solution, or another methode to simply build an Empty ZIP file!!!

Thank's by advance,

Regards.

Share this post


Link to post
Share on other sites
PsaltyDS

Chr(0) is EOF to AutoIt in a string. You might want to assemble that header in a Binary(), and use binary mode for the FileOpen() before writing it.

:)

P.S. Demo (untested, please try it and check with your disk editor):

Func InitZip ($zip_path_name)
    $bin_zipString = Binary("0x504B0506000000000000000000000000000000000000")
    $file = FileOpen($zip_path_name,2 + 16) ; binary mode                 
    FileWrite($file,$bin_zipString);Write the binary in a file
    FileClose($file)
EndFunc

P.P.S. Tweaked second instance of variable name $bin_zipString.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
NDTC

Great!!!!

It's ok... I search since 2 hours, and you found this in 4 minutes...

I searching an another function, but I am sure that others have already created several time: find the parent directory that a folder:

"c:\drivers\test" -> "C:\Drivers" is the parent directory of "Test"

Have you an idea?

Thank you very much...

Share this post


Link to post
Share on other sites
danielkza

Great!!!!

It's ok... I search since 2 hours, and you found this in 4 minutes...

I searching an another function, but I am sure that others have already created several time: find the parent directory that a folder:

"c:\drivers\test" -> "C:\Drivers" is the parent directory of "Test"

Have you an idea?

Thank you very much...

I made this myself because i don't like _Path* functions:

Func _PathDir(Const $Path)
    Local $Pos = StringInStr($Path,"\",0,-1)
    IF Not $Pos Then
        $Pos = StringInStr($Path,"/",0,-1)
        IF NOT $Pos Then
            Return ""
        EndIf
    EndIF
        
    Return StringLeft($Path,$Pos - 1)
EndFunc

By the way,i'm having problems with binary strings to.

I need to format a string like this: "C:\test1\whatever.txt\0\0whatsoever.txt\0\0somemore.txt\0" where \0 are Chr(0) (NULL if you prefer)

How can i do this? (Forgot:the files are in an array,so stringformat won't work)

Edited by danielkza

Share this post


Link to post
Share on other sites
PsaltyDS

By the way,i'm having problems with binary strings to.

I need to format a string like this: "C:\test1\whatever.txt\0\0whatsoever.txt\0\0somemore.txt\0" where \0 are Chr(0) (NULL if you prefer)

How can i do this? (Forgot:the files are in an array,so stringformat won't work)

Why would you want to do that in a string (vice a binary)? Where is that a valid format?

It's not hard to generate as a binary:

Global $avString[3] = ["C:\test1\whatever.txt", "\0whatsoever.txt", "\0somemore.txt"]
Global $binData = ""

For $n = 0 To UBound($avString) - 1
    $binData &= Binary($avString[$n]) & Binary("0x00")
Next

ConsoleWrite("$binData = " & $binData & @LF)

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
danielkza

Why would you want to do that in a string (vice a binary)? Where is that a valid format?

It's not hard to generate as a binary:

Global $avString[3] = ["C:\test1\whatever.txt", "\0whatsoever.txt", "\0somemore.txt"]
Global $binData = ""

For $n = 0 To UBound($avString) - 1
    $binData &= Binary($avString[$n]) & Binary("0x00")
Next

ConsoleWrite("$binData = " & $binData & @LF)

:)

This format is used in windows SHFileOperation function,it's really weird and unusual,but so is all the Windows API.And the problem is that the function does not accept binary data,so i should just use BinaryToString()?

EDIT:Quote from MSDN:

Although this member is declared as a single null-terminated string, it is actually a buffer that can hold multiple null-delimited file names. Each file name is terminated by a single NULL character. The last file name is terminated with a double NULL character ("\0\0") to indicate the end of the buffer.

Edited by danielkza

Share this post


Link to post
Share on other sites
Rick

to create an empty zip just do.....

FileWrite("zipname.zip", Binary("0x504B0506000000000000000000000000000000000000"))


Who needs puzzles when we have AutoIt!!

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×