Jump to content

ZIP UDF (zipfldr.dll library)


wraithdu
 Share

Recommended Posts

First, thank you wraithdu for the work you have done on this UDF. Nice job!

My question may be an easy one. I am writing a script to unzip a number of files one at a time and as part of the process I am attempting to exit when there are errors. One particular error is when the .ZIP file submitted is corrupt or otherwise unusable. In my testing I noted that the _ZIP_UnzipAll function does not seem to return an error when the .ZIP is not a valid file. 

To test this, I took a plain text file, filled it with garbage text and renamed it with a .zip extension. When Windows attempts to open it I receive an alert that the file is unopenable. (The file is invalid) If I take the same file and use the _ZIP_UnzipAll function, no errors are returned and a unzip destination folder is created. I receive a Return Code 1 and an error code of 0. Here is the script that I used to test this issue.

#include <_Zip.au3>

$retcode = _ZIP_UnzipAll("C:\scripts\autoit\ZipProcess\ThisIsNotAZIP.zip","C:\scripts\autoit\ZipProcess\rcvd\unzippedhere")
ConsoleWrite("-- "&@error&" -- "&$retcode&" --"&@CRLF)

Inserting the COM error checking returns no errors either. Any suggestions? AutoIT version is 3.3.10.2

Link to comment
Share on other sites

added another checker to the function:

Func _Zip_UnzipAll($sZipFile, $sDestPath, $iFlag = 20)
    If Not _Zip_DllChk() Then Return SetError(@error, 0, 0)
    If Not _IsFullPath($sZipFile) Or Not _IsFullPath($sDestPath) Then Return SetError(3, 0, 0)
    ; get temp dir created by Windows
    Local $sTempDir = _Zip_TempDirName($sZipFile)
    Local $oNS = _Zip_GetNameSpace($sZipFile)
    If Not IsObj($oNS) Then Return SetError(4, 0, 0)
    $sDestPath = _Zip_PathStripSlash($sDestPath)
    If Not FileExists($sDestPath) Then
        DirCreate($sDestPath)
        If @error Then Return SetError(5, 0, 0)
    EndIf
    Local $oNS2 = _Zip_GetNameSpace($sDestPath)
    If Not IsObj($oNS2) Then Return SetError(6, 0, 0)
    If Not $oNS.Items().count > 0 Then  Return SetError(7, 0, 0)
    $oNS2.CopyHere($oNS.Items(), $iFlag)
    ; remove temp dir created by WIndows
    DirRemove($sTempDir, 1)
    If FileExists($sDestPath & "\" & $oNS.Items().Item($oNS.Items().Count - 1).Name) Then
        ; success... most likely
        ; checks for existence of last item from source in destination
        Return 1
    Else
        ; failure
        Return SetError(8, 0, 0)
    EndIf
EndFunc   ;==>_Zip_UnzipAll

Or:

If Not IsObj($oNS.Items().Item($oNS.Items().Count - 1)) Then  Return SetError(7, 0, 0)

The object should be checked, prior to using a property|method you expect the object to have.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thank you jdelaney, that seems to have done the trick. Would a similar line be needed for the _Zip_Unzip function as well? I have not tested but thought I would ask anyway. Thanks again!

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 1 month later...

First, thank you wraithdu for the work you have done on this UDF. Nice job!

My question may be an easy one. I am writing a script to unzip a number of files one at a time and as part of the process I am attempting to exit when there are errors. One particular error is when the .ZIP file submitted is corrupt or otherwise unusable. In my testing I noted that the _ZIP_UnzipAll function does not seem to return an error when the .ZIP is not a valid file. 

To test this, I took a plain text file, filled it with garbage text and renamed it with a .zip extension. When Windows attempts to open it I receive an alert that the file is unopenable. (The file is invalid) If I take the same file and use the _ZIP_UnzipAll function, no errors are returned and a unzip destination folder is created. I receive a Return Code 1 and an error code of 0. Here is the script that I used to test this issue.

#include <_Zip.au3>

$retcode = _ZIP_UnzipAll("C:\scripts\autoit\ZipProcess\ThisIsNotAZIP.zip","C:\scripts\autoit\ZipProcess\rcvd\unzippedhere")
ConsoleWrite("-- "&@error&" -- "&$retcode&" --"&@CRLF)

Inserting the COM error checking returns no errors either. Any suggestions? AutoIT version is 3.3.10.2

 

Similar situation to my earlier issue, tested with the same methods, I've noted that _Zip_Count does not fail with a bad ZIP file. I've tinkered with the suggestions posted by @jdelaney above (which works in the _Zip_UnzipAll function) but could not get it to fail. I confess that my understanding of insides of this UDF is weak. Can someone help me tweak for better error handling?

Not sure of other functions and whether they handle bad ZIP files. Might be worth investigating. Also noted the process does not fail with _Zip_Unzip and _Zip_Search as well.

Edited by gritts
Link to comment
Share on other sites

  • 3 months later...

I managed to do what I wanted to do without asking for help :)

Was trying to make a simple daily archive for people who scan in a lot of PDF files.

I was working with the old Zip.au3 at first but it was throwing some strange errors from the UDF itself, then I found this one

My major hurdle was I was trying to add entire folder contents and that function was removed.  So I settled for just adding the entire folder including its contents.

That worked fine until I tried the scenario where somebody tried to archive more than one time in the same day.  I could not in any way no matter what flags I used get the files to "append" to existing files in the .zip

So as much as I did not want too because I am not so great at it, I had to go for a loop and add the files individually.  This fixed the issue.

I think maybe the folder level would have worked had I noticed that if you use "0" for do not overwrite on _Zip_Create that you do not get a handle and instead get an @Error return.  This may have been why it was not working

That is when I re-declared the varible with the file path based on an @Error = 1 result.

Since I have it working at the file level I have no intentions of going back to adding the folder.

I'll share my script so that it can be critiqued and maybe useful

 
;Needed UDFS
#Include <_Zip.au3>
#include <File.au3>
#include <Array.au3>

;Path Varibles
$ArchiveSorc = @ScriptDir
$ArchiveDest = "H:\Scans Archive\"
$ArchiveTmp = @MyDocumentsDir & "\DailyArchive\"

;Msgbox Confirmation 6= Yes Else Exit
$Choice = MsgBox(4, "Black Magic Archive Tool", "Are you ready to archive all .PDF files from your Local Scans folder to your Archive Folder?")
If $Choice = 6 Then

DirCreate($ArchiveDest)
;File Move 9 = Overwrite
FileMove($ArchiveSorc & "\*.pdf", $ArchiveTmp, 9)
;ZipCreate 0 Do not Overwrite
$ZipNow = _Zip_Create($ArchiveDest & @MON & "-" & @MDAY & "-" & @YEAR & " Archive.zip", 0)
If @Error = 1 Then $ZipNow = $ArchiveDest & @MON & "-" & @MDAY & "-" & @YEAR & " Archive.zip"
;@Error 1 = File Already Exsists

;Puts all file names into an Array
$FileList = _FileListToArray($ArchiveTmp)

; Debugging See the Array Values In Window
;_ArrayDisplay($FileList)

For $i = 1 To UBound($FileList) - 1
    ;Debugging See the Current i and array value used in loop
    ;MsgBox(0, "", "Current i Value " & $i & " making current array value" & $FileList[$i])
_Zip_AddItem($ZipNow, $ArchiveTmp & $FileList[$i])

Next

;Delete Temp Folder to keep Computer HDD Clean and Purge Files
FileDelete($ArchiveTmp)
MsgBox(0, "Black Magic Archive Tool", _Zip_Count($ZipNow) & " Items are now in your .ZIP Archive located at " & $ArchiveDest)
Exit

Else
    Exit
EndIf
 

for somebody else.

Edited by ViciousXUSMC
Link to comment
Share on other sites

  • 1 month later...

Getting some interesting results when combining this UDF with a GUI. if I try to add an item to a zip that doesn't have a filename that can be compressed. It throws an error that for some reason causes the GUI's controls to stop working. I cannot determine if this is something wrong with my GUI or if the _Zip_additem function is attempting to repeatedly add the item causing the script to lock. Any advice would be appreciated.

Link to comment
Share on other sites

  • Moderators

natwolf,

Posting the code you use would be a help as otherwise we are relying on our crystal balls - and mine is playing up at the moment. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Going to need to trim a lot of fat because the real version is mostly obfuscated and does a lot more but this should give the basic tense of where I encounter my troubles. Please forgive sloppiness I did it quick :)

#include<_Zip.Au3>
#include<Guiconstants.Au3>
#include<File.au3>

Guicreate("Example", 200, 100)

$addfolder = Guictrlcreatebutton("Add Folder", 10, 50, 75, 25)
$Addfile = Guictrlcreatebutton("Add File", 110, 50, 75, 25)

Guisetstate(@SW_Show)

while 1


switch Guigetmsg()

Case $gui_event_close
    Exit


case $addfolder
$itemtoadd = Selectfolder()
Addtozip($itemtoadd)

case $addfile
$itemtoadd = Selectfile()
addtozip($itemtoadd)

endswitch


wend

Func Selectfile()

    $file = FileOpenDialog("Please select file to add", "C:\", "ALL(*.*)")

    return $file
EndFunc

Func Selectfolder()
    $directory = FileSelectFolder("Please select folder to add", "C:\") & "\"

    return $directory
EndFunc

Func addtozip($itemtoadd)
    $zipfile = @tempdir & "\Example.zip"

    _Zip_create($zipfile)

    _zip_additem($zipfile, $itemtoadd)

EndFunc
Link to comment
Share on other sites

  • Moderators

natwolf,

That code is running perfectly for me - I can add folders and files to the zip with no problem at all - the GUI remains active throughout. Do you have a specific order of actions which result in a lockup? Or a specific file which produces the lockup when added? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Yep sure do. It just seems to be any file that will cause it to throw an error that it cannot be compressed. weather special character in its name or foreign ones...foreign character ones seem to be biggest problem so the attached one should work. I understand why it cannot add it to the zip, makes total sense just trying to find a way having it avoid locking up the gui after.

don't know if I attached that file correctly. default name for it is: 下拉list.png

post-85903-0-22587300-1425291651_thumb.p

Edited by natwolf
Link to comment
Share on other sites

  • Moderators

natwolf,

If we are into unicode filenames then I am afraid I cannot help. In fact I cannot even rename that file to the name you provided. :(>

But I see there is a loop in the _Zip_AddItem function which might well be the cause of your lockup problem. Try copying this amended function to the same folder as _Zip.au3 and call the modified _Zip_AddItem_Mod in your script:

Func _Zip_AddItem_Mod($sZipFile, $sItem, $sDestDir = "", $iFlag = 21)
    If Not _Zip_DllChk() Then Return SetError(@error, 0, 0)
    If Not _IsFullPath($sZipFile) Then Return SetError(3, 0, 0)
    If Not _IsFullPath($sItem) Then Return SetError(4, 0, 0)
    If Not FileExists($sItem) Then Return SetError(5, 0, 0)
    If _IsFullPath($sDestDir) Then Return SetError(6, 0, 0)
    ; clean paths
    $sItem = _Zip_PathStripSlash($sItem)
    $sDestDir = _Zip_PathStripSlash($sDestDir)
    Local $sNameOnly = _Zip_PathNameOnly($sItem)
    ; process overwrite flag
    Local $iOverwrite = 0
    If BitAND($iFlag, 1) Then
        $iOverwrite = 1
        $iFlag -= 1
    EndIf
    ; check for overwrite, if target exists...
    Local $sTest = $sNameOnly
    If $sDestDir <> "" Then $sTest = $sDestDir & "\" & $sNameOnly
    Local $itemExists = _Zip_ItemExists($sZipFile, $sTest)
    If @error Then Return SetError(7, 0, 0)
    If $itemExists Then
        If @extended Then
            ; get out, cannot overwrite folders... AT ALL
            Return SetError(8, 0, 0)
        Else
            If $iOverwrite Then
                _Zip_InternalDelete($sZipFile, $sTest)
                If @error Then Return SetError(10, 0, 0)
            Else
                Return SetError(9, 0, 0)
            EndIf
        EndIf
    EndIf
    Local $sTempFile = ""
    If $sDestDir <> "" Then
        $sTempFile = _Zip_AddPath($sZipFile, $sDestDir)
        If @error Then Return SetError(11, 0, 0)
    EndIf
    Local $oNS = _Zip_GetNameSpace($sZipFile, $sDestDir)
    ; copy the item(s)
    $oNS.CopyHere($sItem, $iFlag)
    
    ; ###################################
    
    Local $nBegin = TimerInit()
    Do
        Sleep(250)
        If TimerDiff($nBegin) > 10 * 1000 Then Return SetError(13, 0, 0)
    Until IsObj($oNS.ParseName($sNameOnly))
    
    ; ###################################
    
    If $sTempFile <> "" Then
        _Zip_InternalDelete($sZipFile, $sDestDir & "\" & $sTempFile)
        If @error Then Return SetError(12, 0, 0)
    EndIf
    Return 1
EndFunc   ;==>_Zip_AddItem_Mod
As you can see I have added a timeout to the loop - check the error returned to see if it was activated (13). :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23

I tried the _zip_additem_Mod. After the timer complete the GUI was no longer locked and the yes it did return Error 13 so your theory for where the problem was coming from was correct :)

I've seen it with other file names that was just the one I had handy but your help is very much appreciated!

Link to comment
Share on other sites

  • Moderators

natwolf,

Glad I could cure the symptoms even if not the root cause! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 weeks later...

It seems UDF cannot work with unicode filemanes... Is there a way to fix this?

see reproducer for list function (save script  as UTF16LE and insert  path to any valid zip archive)

#include <Array.au3>
#include "_Zip - ZIP UDF (zipfldr.dll library).au3"

$sPathToCurrentArc = ".....zip"

If StringIsASCII($sPathToCurrentArc) Then
    $sPathToCurrentArcNew = StringRegExpReplace($sPathToCurrentArc,"\\[^\\]*\z","") & "\いくつかのUnicodeのファイル名.zip"
    FileCopy($sPathToCurrentArc,$sPathToCurrentArcNew)
    $sPathToCurrentArc = $sPathToCurrentArcNew
EndIf
$aArcFileList = _Zip_ListAll(FileGetShortName($sPathToCurrentArc), 1)
_ArrayDisplay($aArcFileList,"@error = " & @error & " - " & FileGetShortName($sPathToCurrentArc))
Link to comment
Share on other sites

  • 1 year later...

Same problem here, that's beeing discussed in the other zip UDF Thread. This UDF (and the other ZIP UDF) no longer work for Windows 10. I remember that it worked a few month ago, but now there's always an error when adding Files to previously created ZIP-Files.

Only for Windows 10. Testet the exact same piece of code on Windows 7 and it works.
So apparently Microsoft changed something with an update ..

Will there be an update for this UDF too?

Link to comment
Share on other sites

  • 8 months later...

I'm trying to do something that may be impossible. I want to check the date of files in a zip file so that I can zip the new version in the scriptdir... I think the line that's giving me problems is

$oApp = ObjCreate("Shell.Application")
    $hList = $oApp.Namespace($hZipFile).Items
    For $item in $hList
        _ArrayAdd($aArray,$item.name)
    Next

I tried changing it to

_ArrayAdd($aArray,$item.type)

and it worked - it gave me the type of each file in the archive. However when I try

_ArrayAdd($aArray,$item.Date Modified)

it doesn't work... Help, what can I do?

Blessings

Graeme

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