Jump to content

Error unzipping files with 7zip


Recommended Posts

Hello

I am new to Autoit but taking to it pretty well. I love it but I’m having trouble using 7zip to unzip files into a folder. I am running a 64-bit compiled Autoit exe on W2008R2 install two programs and import post install configurations. I had the line of code below in the file and it failed. I pulled the code out and created a separate exe. The code works flawlessly in its own executable.

-----------------------------------------------------------------

;Copy install files into the Temp directory

FileInstall ("7za.exe", @TempDir & "7za.exe", 1)

FileInstall ("file1.zip", @TempDir & "file1.zip", 1)

FileInstall ("file2.zip", @TempDir & "file2.zip", 1)

FileInstall ("file3.zip", @TempDir & "file3.zip", 1)

FileInstall ("file4.zip", @TempDir & "file4.zip", 1)

;Import files

Run(@ComSpec & ' /c  ' & @TempDir & '7za x file1.zip -o"C:folder1" -aoa', " ", "@SW_HIDE")

Run(@ComSpec & ' /c  ' & @TempDir & '7za x file2.zip -o"C:folder2" -aoa', " ", "@SW_HIDE")

Run(@ComSpec & ' /c  ' & @TempDir & '7za x file3.zip -o"C:folder3" -aoa', " ", "@SW_HIDE")

Run(@ComSpec & ' /c  ' & @TempDir & '7za x file4.zip -o"C:folder4" -aoa', " ", "@SW_HIDE")

 

Exit

----------------------------------------------------------------

However, when I add these same lines of code without the @SW_HIDE and with ‘ /k ‘ (to see the errors) I get the error:

'C:UsersADMINI~1AppDataLocalTemp27za' is not recognized as an internal or external command, operable program or batch file.

C:UsersAdministratorDesktop Install Files>

I tried calling the working exe from within the first exe but it still fails with the same error. Worst case I can deploy an install exe and a post install exe file but I would really like just one install file if at all possible. I have searched everywhere and I have been banging my head against this for 2 days. I need to release this tomorrow for a critical update so a set of fresh eyes would be wonderful. Thanks.

Edited by sircodealot
Link to comment
Share on other sites

Why bother with a third party utility? I had the same problems and resolved it with a lot less code. You could in theory do the same as I have written below and modify it into a working function in your situation.

#include <Process.au3>

Func UnZip($Directory, $File)  
      FileWrite("UnZIP.vbs", 'strZipFile = "' & @ScriptDir & '\' & $Directory & '\' & $File & '.zip"' & @CRLF & 'outFolder = "' & @ScriptDir & '\' & $Directory & '\"' & @CRLF & 'Set objShell = CreateObject( "Shell.Application" )' & @CRLF & 'Set objSource = objShell.NameSpace(strZipFile).Items()' & @CRLF & 'Set objTarget = objShell.NameSpace(outFolder)' & @CRLF & 'intOptions = 256' & @CRLF & 'objTarget.CopyHere objSource, intOptions')
      _RunDos("start " & @ScriptDir & "\UnZIP.vbs")
      Sleep("5000")
      FileDelete("UnZIP.vbs")
      FileDelete("" & @ScriptDir & "\" & $Directory & "\" & $File & ".zip")
EndFunc

But, In regards to your code, Have you tried attaching ".exe" after the 7za in your Run code?

Edited by BlackDawn187
Link to comment
Share on other sites

Thanks Wayfaer I used 7zip because that's what I saw was recommended. I don't understand your code. It looks like you are using a vbs called UZIP. Where would I get this? Also, wouldn't including <process.au3> just make my exe larger? I'm using the code from _RunDOS in that au3 file directly in my code so I shoundn't need it if I am following this correctly. What I am not following is where to modify this to put my file names. There are a lot of variables in your code. It's a little confusing for my tired eyes. But hey... thanks for replying. If I can muddle through it I will let you know if it works.

I have tried using 7za.exe and get the same results. What's bothering me most is why this works in a stand alone exe but doesn't work inside my main exe. And more over, if it works as a stand alone exe, why doesn't it work when I call it from my main exe. I'm baffled.

Link to comment
Share on other sites

Sorry, I can't really help troubleshoot the problems you're having with 7zip and, Your script errors. But, As for my script I attached, It creates a file called UnZip.vbs. Seeing as most windows operating systems have vbs natively installed, I prefer to use local utilities versus installing 7zip. I'll try to elaborate on what exactly the code does. But, In regards to the #include, It's only there to permit the _RunDos ability. If you already have it included in your script you can delete that line.

The Function UnZip, Accepts two parameters $Directory and, $File. In my situation I was unzipping into a directory within my @ScriptDir. So for your purposes everything referencing $Directory may have to be deleted or replaced. $File is the predetermined name of your zip file that you want to unzip. This function should be called like such: Call("UnZip", $Directory, $File). For simplicity sake I've attached a working, Better suited for your needs script;

#include <Process.au3>
$Directory = "" & @ScriptDir & ""
$File = "file1"
Call("UnZip", $Directory, $File)

Func UnZip($Directory, $File) 
      FileWrite("UnZip.vbs", 'strZipFile = "' & $Directory & '\' & $File & '.zip"' & @CRLF & 'outFolder = "' & $Directory & '\"' & @CRLF & 'Set objShell = CreateObject( "Shell.Application" )' & @CRLF & 'Set objSource = objShell.NameSpace(strZipFile).Items()' & @CRLF & 'Set objTarget = objShell.NameSpace(outFolder)' & @CRLF & 'intOptions = 256' & @CRLF & 'objTarget.CopyHere objSource, intOptions')
      _RunDos("start " & @ScriptDir & "\UnZIP.vbs")
      Sleep("5000")
      FileDelete("UnZIP.vbs")
      FileDelete("" & $Directory & "\" & $File & ".zip")
          Return
EndFunc

All you have to do is call the function from your script and declare the $Directory & $File variables accordingly. Maybe throw in a error check.. The only thing I don't like about this script is that if there's an existing file it will display a copy & replace dialog. Though, I'm sure someone more technical with vbs could eliminate that.

Edited by BlackDawn187
Link to comment
Share on other sites

I think I figured it out. Silly as it sounds I'm pretty sure the failure was because there was no sleep delay. The files were going into the TempDir and being deleted by the FileDelete cleanup before they were unable to unzip. I added a few Sleep delays and it works now. I feel silly .... :)

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