topten

Unzip your files without progress bar

15 posts in this topic

Very simple: I had seen many examples of unzipping files (Zip) archive, but most of those example where using either some external .dll or are performing the job with the progress bar. Here is a small example how you can unzip your files without any external libraries and without any progress bar

$ZipFile5="C:\file.zip"
$ExtractTo5="C:\folder"



$objShell5 = ObjCreate ("Shell.Application")
$FilesInZip5=$objShell5.NameSpace($ZipFile5).items
$objShell5.NameSpace($ExtractTo5).CopyHere($FilesInZip5,0x4)

Enjoy :)

1 person likes this

Share this post


Link to post
Share on other sites



performing the job with the progress bar

??? Progress bar? You can extract zip files using a progress control!? :P


Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

By "progress bar" I mean - the windows progress bar which is showing- that your files are moving from one directory to another. And if you have say 10000 files in zip file? So if you don't like that win progress bar- this example is right for you :)

Ah, btw- if you do want the progress bar, then just remove this part from the code

,0x4
Edited by topten

Share this post


Link to post
Share on other sites

Oh :o...


Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Nice, what limitation of OS does this have being object based (XP, 7, Vista, 8, 10)

I wrote a program to update maps for a 911 system and hated how the transfer dialog came up when the file was done downloading.

Edit: Here we go a copy of my code updated with this method.
I commented out the 2 lines that were doing the unzipping before, and I can remove the Include for Zip.au3

I noticed that you must have the directory already or this will not work so I added in the DirCreate()

My question here is how I was checking the return of the _Zip_UnzipAll() for log file usage.  How can I check the return of this unzip method so I can log the results accurately?

#Include <Array.au3>
#Include <File.au3>
#Include <Zip.au3>

$sMaps = "C:\Tiburon\"  ;Where To Save Maps

$aZip = _FileListToArray("C:\Tiburon", "*.zip", $FLTA_FILES, True) ;Get A List of All .Zip Files
If @Error Then ;If No Downloads Exit
    ;MsgBox(0, "", @Error)
    Exit
Else ;Else Get The Highest Version Map .Zip Package and Save to $sZip and get Name and save in $sMap2
    ;_ArrayDisplay($aZip)
    $sZip = $aZip[$aZip[0]]
    $aMap = StringSplit($sZip, "\")
    $sMap2 = StringTrimRight($aMap[$aMap[0]], 4)
    $sMaps &= $sMap2
EndIf

$sLogPath = "C:\Tiburon\" & $sMap2 & ".log" ;Create Our Log File Path with $sMap2 as the Name
_FileWriteLog($sLogPath, "New Map Package " & $sMap2 & " was downloaded") ;Write To Log that The .Zip was downloaded
$vStep1 = DirRemove($sMaps, 1) ;If Zip was Already Extracted Delete As To Extract New (Prevent Corrupted Downloads)
If $vStep1 = 1 Then _FileWriteLog($sLogPath, "Deleted old " & $sMap2 & " folder") ;Write To Log That Old Folder Was Found and Deleted
DirCreate($sMaps)
$objShell5 = ObjCreate("Shell.Application")
$FilesInZip5 = $objShell5.NameSpace($sZip).items
$objShell5.NameSpace($sMaps).CopyHere($FilesInZip5,0x4)
;$vStep2 = _Zip_UnzipAll($sZip, $sMaps, 1) ;Unzip Our File
;If $vStep2 = 0 Then _FileWriteLog($sLogPath, "Successfully Unziped Package for " & $sMap2) ;Log That We Unzipped Our File
$vStep3 = FileDelete($sZip) ;Delete Zip Package When Finished
If $vStep3 = 1 Then _FileWriteLog($sLogPath, "Successfully Deleted " & $sMap2 & " .Zip Package") ;Log That We Deleted Our Zip File Successfully

 

Edited by ViciousXUSMC

Share this post


Link to post
Share on other sites

ViciousXUSMC ,

"How can I check the return of this unzip method so I can log the results accurately?"

I  am not sure yet about how to check the return, I will try to research that question.

 

In my case- the script was waiting untill the files are unzipped and then it went on further execution

Share this post


Link to post
Share on other sites

ViciousXUSMC,

But what actually are you trying to achieve by logging?

Share this post


Link to post
Share on other sites

$ZipFile5="C:\Users\Abhishek\Downloads\BackPack_Resources\ComputerSystemsManagement_Lectures.zip"
   $ExtractTo5="C:\Users\Abhishek\Downloads\BackPack_Resources\CSE131\Lectures"
   $objShell5 = ObjCreate ("Shell.Application")
   $FilesInZip5=$objShell5.NameSpace($ZipFile5).items
   $objShell5.NameSpace($ExtractTo5).CopyHere($FilesInZip5,0x4)

 

I used this code for extracting my homework but I got this error instead:-

$FilesInZip5=$objShell5.NameSpace($ZipFile5).items
$FilesInZip5=$objShell5.NameSpace($ZipFile5)^ ERROR

What Could be the possible reason.
I am using this inside a function

 

Share this post


Link to post
Share on other sites

You need to add some error checking to your script. Look at IsObj in the help file, and look at placing it there after your ObjCreate statement. You can also try running the script with #RequireAdmin at the top.


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

isObj is returning 0 for  ($ZipFile5)

this means it is not a object variable.
where could I have gone wrong?

Share this post


Link to post
Share on other sites

Did you try with #RequireAdmin? You need to error check the rest of the script:

  • Confirm the zip file exists in the directory you reference in line 1
  • Confirm the directory you reference in line 2 is accessible, and you have rights to it
  • Confirm you can create the Shell.Application in line 3
  • etc. etc. etc.

Look at @error and FileExists in the help file.


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Okay, Its working Now.
I just copied the code outside the function i had defined

But when I copied it back inside the function it stops working again

Any Clue?

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

  • Similar Content

    • rootx
      By rootx
      There is a way to unzip a file without using other party software, or can I include 7zip without licensing issues,  Thx
    • ur
      By ur
      There is a build machine in the network where it will automatically download the code from source repository and compile using visual studio and compresses the complete code in a zip file.
      I have added a line at the end of the build script(written in python on that machine) to copy that zip file to my ESX Virtual machine.
      Where I kept a AutoIT exe to wait for the zip file, once it is copied then I will extract the contents and find only the dll files in the extracted folder and do the Install creation using Installshield silently and copy the created setup files to anther machine.
      I wrote the script till the setup files creation.
       
      But now the problem is, when the zip file is copying through network, the autoit script is detecting it even the copy is still in progress and trying to extract the zip file and failing.
      Even when I am checking whether the file in use is not working.
       
      Any suggestion on how to check whether the copy is completed.?
    • Comboku
      By Comboku
      Hi guys,
      i hope i am in the right place for this question as it is in regards to zip.au3.
      I have some encrypted files on my harddrive which zip.au3 can't open. This is perfectly fine. The Problem is that it crashes my program as soon as it tries to access the file.
      Is there a way to detect if the file is encrypted BEFORE autoit tries to open it? I am using _zip_unzipall to unzip the file, i also tried _zip_count with the same result. My files are encrypted with SafeGuard Lan Crypt. 
       
      Thanks,
      Comboku
       
    • j0kky
      By j0kky
      Hi guys,
      I often need zipping\unzipping function within my scripts, so I've decided to do a systematic research about it to understand which options I had. I'm sharing with you these results because I think it can save some time to somobody
      Autoit coders produced much material from 2005 till now, most of it consists of UDF wrappers of 3rd parts libraries, but there are some exception.
      Let's start:
      ZIP from scratch UDF: written by joakim. You can retrieve some info from a zip file, but it is just a PoC script, as I can see. LZ UDF: written by trancexx: another exception. It use native windows compression, so it doesn't need anything. It can work with memory, it doesn't work with files. LZMA UDF: written by Ward. He writes a dll which can be directly included or can be embedded within an au3 file. It can work with memory, it doesn't work with files. [it needs LZMA.dll or LZMA.dll.au3](link missing) Package UDF: written by Yashied. It is useful for dealing with package (.pkr) file. ZIP UDF: written by Wraithdu (yet torels UDF): the exception! Based on zipfldr.dll, a native library of Windows, so it does not need to include an external library into the script. It is its strenght, but its weak point too: if zipfldr.dll is corrupted or is missing, your script will not do what you expect. gZip UDF: written by Zinthose. Based on the parsing of gZip.exe output. It can work with memory, it doesn't work with files. [it needs gZip.exe] ZLib UDF: written by monoceres. Based on ZLib.dll. It can compress\uncompress data in memory, it doesn't work with files. [it needs ZLib.dll] pZip UDF: written by asdf8. Based on ZLib.dll. It can extract\add\overwrite file into archives. [it needs pZip.dll] ZLib and gZip UDF: written by Ward. Based on ZLib.dll but it does not need the dll file, because it is written directly in the UDF! It can compress\uncompress data in memory, and it can work with files. It works with gZip format too. (link missing) XZip UDF: written by eltorro, KXM and erifash. Based on XZip.dll, a COM dll. [it needs XZip.dll] XZip UDF: written by mLipok. Based on XZip.dll, a COM dll. A more complete alternative to previous UDF. [it needs XZip.dll] unRAR UDF: written by rasim. Based on unRAR.dll. You can just uncompress rar files with this one (the only method for new v5 RAR files). [it needs unRAR.dll] Parsing unRAR.exe output: you can just uncompress rar files in this way (the only method for new v5 RAR files). [it needs unRAR.exe] 7Zip: I spent a lot of time with it, because I think it is the most useful, there are different approaches: Parsing 7za.exe output, it is the simplest (and in my opinion the best) way, some UDFs can help with it, as jennico UDF (thanks to Screen Scrape script by Valik, it seems it doesn't work in Windows 10) [it needs 7za.exe] Using 3rd part dll, as rasim UDF (yet jak UDF). He rewrites a dll which can be simply invoked by his UDF [it needs 7-zip32.dll and\or 7-zip64.dll]. With Decipher UDF you doesn't need to include the dll in your project, because it is compiled into the script and loaded in memory directly at runtime. Invoking 7za.dll. This is the most complicated approach because the library doesn't use standard COM interfaces. Anyway dany, Starg, milky, trancexx, Mugen and finally Biatu had spent some time with it and they reach a sort of partial result. [it needs 7za.dll]  
      Comment here to add suggestions\links\UDF I forgot and I'll update this post with them!
    • afallenhope
      By afallenhope
      Hello all!
      I have run into a bit of trouble with a project that I am working on. I currently have an autoit file calling a  java script to  go out and retrieve the latest install of X from an FTP Server. It works great! Well the problem I am running into now is since the file I grab is zipped I have to unzip so then I can run the installation for X. I thought I had found a way using 7-zip but I keep getting an error even if I try to run the installation myself saying "Error: Error loading XML file.. This application will now close." If I extract the files using windows explorer I am able to install the program. 
      I have my autoit file calling this .bat file and as a result I am unable to load from the unzipped folder due to this error loading XML file.
      cd "C:\Program Files (x86)\7-zip"
      7z e "C:\Users\NTS User\Documents\AutoInstall\XInstall.zip" -o"C:\Users\NTS User\Desktop\Autoit\X" -y
       
      Am I missing something with this? If anyone could provide insight I would deeply appreciate it. Thanks again! 
       
      Richard
      P.S. If I forgot to include anything just let me know!