skysel Posted April 2, 2008 Share Posted April 2, 2008 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? expandcollapse popupDim $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 More sharing options...
DarkMatter Posted April 2, 2008 Share Posted April 2, 2008 Where are you calling your InitZip function at? [sub]Quantum mechanics: The dreams stuff is made of[/sub] Link to comment Share on other sites More sharing options...
skysel Posted April 2, 2008 Author Share Posted April 2, 2008 Where are you calling your InitZip function at?I used script from http://www.autoitscript.com/forum/index.ph...21004&st=15Deleted few unneeded parts (prompt dialogs). And that was basicaly it Link to comment Share on other sites More sharing options...
DarkMatter Posted April 2, 2008 Share Posted April 2, 2008 (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 April 2, 2008 by DarkMatter [sub]Quantum mechanics: The dreams stuff is made of[/sub] Link to comment Share on other sites More sharing options...
skysel Posted April 2, 2008 Author Share Posted April 2, 2008 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 More sharing options...
DarkMatter Posted April 2, 2008 Share Posted April 2, 2008 (edited) expandcollapse popupDim $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 April 2, 2008 by DarkMatter [sub]Quantum mechanics: The dreams stuff is made of[/sub] Link to comment Share on other sites More sharing options...
skysel Posted April 2, 2008 Author Share Posted April 2, 2008 expandcollapse popupDim $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 More sharing options...
DarkMatter Posted April 2, 2008 Share Posted April 2, 2008 (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 April 2, 2008 by DarkMatter [sub]Quantum mechanics: The dreams stuff is made of[/sub] Link to comment Share on other sites More sharing options...
skysel Posted April 2, 2008 Author Share Posted April 2, 2008 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. Link to comment Share on other sites More sharing options...
DarkMatter Posted April 2, 2008 Share Posted April 2, 2008 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] Link to comment Share on other sites More sharing options...
skysel Posted April 3, 2008 Author Share Posted April 3, 2008 (edited) Here it is... expandcollapse popupDim $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 April 3, 2008 by skysel Link to comment Share on other sites More sharing options...
DarkMatter Posted April 3, 2008 Share Posted April 3, 2008 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] 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