Jump to content

ZIP Integration


Recommended Posts

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)
Link to comment
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.

Edited by DarkMatter

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

Link to comment
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..
Link to comment
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)

Edited by DarkMatter

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

Link to comment
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 :)
Link to comment
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)
Edited by DarkMatter

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

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

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