Sign in to follow this  
Followers 0
skysel

ZIP Integration

12 posts in this topic

So, i've read on the forums about the zip feature. Here's what I put together (decided to rather use winxp api instead of external 7za.exe):

Problem being, it says that compressed folder is corrupted upon running the program... Where did I go wrong? :)

Dim $sourceFolder = "C:\"
Dim $filename = @UserName & "." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".zip"
Dim $sharedFolder = "\\vd-cc-mihav\AIC log collect"
Dim $newFilename = $filename & $ext

Dim $Shell,$srcFolder,$DestFolder,$items;Objects

Const $BIF_BROWSEINCLUDEFILES = 0x4000
Const $ssfPERSONAL = 0x5;My Documents directory

$Shell = ObjCreate("Shell.Application")

$Destfolder = "C:\" & $newFilename
$srcFolder = "C:\Program Files\Avaya\IC71\logs"

$Shell.NameSpace($DestFolder).Copyhere ($srcFolder,0)

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


If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

FileCopy ($sourceFolder & "\" & $filename & $ext, $sharedFolder & "\" & $newFilename)

Share this post


Link to post
Share on other sites



Where are you calling your InitZip function at?


[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

In the example you will see:

If @error = 1 then
$DestFolder = $shell.browseforfolder(0,"Pick Destination Folder or Zip",$BIF_BROWSEINCLUDEFILES)
Else
    initzip($answer)
    $Destfolder = $answer
EndIF

In your code you have the function for InitZip but I do not see it being called. If that isn't called then the zip file will have incorrect headers and will appear to be corrupted.

Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Share this post


Link to post
Share on other sites

In the example you will see:

If @error = 1 then
$DestFolder = $shell.browseforfolder(0,"Pick Destination Folder or Zip",$BIF_BROWSEINCLUDEFILES)
Else
    initzip($answer)
    $Destfolder = $answer
EndIF

In your code you have the function for InitZip but I do not see it being called. If that isn't called then the zip file will have incorrect headers and will appear to be corrupted.

So what should be done to fix the code? Copy this piece of code into my existing? (I really ain't much of an expert :)) Still learning..

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Dim $sourceFolder = "C:\"
Dim $filename = @UserName & "." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".zip"
Dim $sharedFolder = "\\vd-cc-mihav\AIC log collect"
Dim $newFilename = $filename & $ext

Dim $Shell,$srcFolder,$DestFolder,$items;Objects

Const $BIF_BROWSEINCLUDEFILES = 0x4000
Const $ssfPERSONAL = 0x5;My Documents directory


$Shell = ObjCreate("Shell.Application")

$Destfolder = "C:\" & $newFilename
$srcFolder = "C:\Program Files\Avaya\IC71\logs"

InitZip($DestFolder);This is the piece you are missing...

$Shell.NameSpace($DestFolder).Copyhere ($srcFolder,0)

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


If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

FileCopy ($sourceFolder & "\" & $filename & $ext, $sharedFolder & "\" & $newFilename)

Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Share this post


Link to post
Share on other sites

Dim $sourceFolder = "C:\"
Dim $filename = @UserName & "." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".zip"
Dim $sharedFolder = "\\vd-cc-mihav\AIC log collect"
Dim $newFilename = $filename & $ext

Dim $Shell,$srcFolder,$DestFolder,$items;Objects

Const $BIF_BROWSEINCLUDEFILES = 0x4000
Const $ssfPERSONAL = 0x5;My Documents directory


$Shell = ObjCreate("Shell.Application")

$Destfolder = "C:\" & $newFilename
$srcFolder = "C:\Program Files\Avaya\IC71\logs"

InitZip($DestFolder);This is the piece you are missing...

$Shell.NameSpace($DestFolder).Copyhere ($srcFolder,0)

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


If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

FileCopy ($sourceFolder & "\" & $filename & $ext, $sharedFolder & "\" & $newFilename)
Still gives me an error that compressed file is corrupted :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The FileWrite was stripping the 18 zeros off the end of the string.

Change the

$file =FileOpen($zip_path_name,2)
to
$file =FileOpen($zip_path_name,18)
Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Share this post


Link to post
Share on other sites

The FileWrite was stripping the 18 zeros off the end of the string.

Change the

$file =FileOpen($zip_path_name,2)
to
$file =FileOpen($zip_path_name,18)
Still the same... Corrupted.

Share this post


Link to post
Share on other sites

Still the same... Corrupted.

Post your full code with the change if you don't mind.


[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Here it is...

Dim $sourceFolder = "C:\"
Dim $filename = @UserName & "." &  @MDAY & "." &  @MON & "." & @YEAR
Dim $ext = ".zip"
Dim $sharedFolder = "\\vd-cc-mihav\AIC log collect"
Dim $newFilename = $filename & $ext

Dim $Shell,$srcFolder,$DestFolder,$items;Objects

Const $BIF_BROWSEINCLUDEFILES = 0x4000
Const $ssfPERSONAL = 0x5;My Documents directory

$Shell = ObjCreate("Shell.Application")

$Destfolder = "C:\" & $newFilename
$srcFolder = "C:\Program Files\Avaya\IC71\logs"

InitZip($DestFolder)

$Shell.NameSpace($DestFolder).Copyhere ($srcFolder,0)

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,18)                        
    FileWrite($file,$init_zipString)       ;Write the string in a file    
    FileClose($file)    
EndIf

EndFunc

If FileExists($sharedFolder & "\" & $filename & $ext) Then
$num = 1
Do
$newFilename = $filename & "-" & $num & $ext
$num += 1
Until NOT FileExists($sharedFolder & "\" & $newFilename)
EndIf

FileCopy ($sourceFolder & "\" & $filename & $ext, $sharedFolder & "\" & $newFilename)
Edited by skysel

Share this post


Link to post
Share on other sites

I just ran your sample code with just a change on $srcFolder. It ran with no issues. Does the logs folder that you are trying to zip have sub folders in it?


[sub]Quantum mechanics: The dreams stuff is made of[/sub]

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  
Followers 0