Jump to content

ZIP UDF (zipfldr.dll library)


wraithdu
 Share

Recommended Posts

Won't the dll accept network paths, such as "\\server\..."?

If so, can you change _IsFullPath() to accept remote paths?

Replace the _IsFullPath() function in ZIP.au3 with this one

Func _IsFullPath($sPath)
    If StringRegExp($sPath, '^([a-zA-Z]\:|\\\\[^\/\\:*?"<>|]+\\[^\/\\:*?"<>|]+)(\\[^\/\\:*?"<>|]+)+$') Then
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>_IsFullPath
Link to comment
Share on other sites

  • 2 weeks later...

I am getting error 7 when I try to add a subdirectory using the command

$ZReturn = _Zip_AddItem($Zip,$AFile,"test",1)

test being the subdirectory. If I use "" everything gets added fine.

No matter what I use as a subdirectory I get the error 7.

I am open to try whatever is needed.

I am running on a Win 7 pro environment.

Thanks,

Rob

Link to comment
Share on other sites

I am getting error 7 when I try to add a subdirectory using the command

$ZReturn = _Zip_AddItem($Zip,$AFile,"test",1)

test being the subdirectory. If I use "" everything gets added fine.

No matter what I use as a subdirectory I get the error 7.

In further research of this error..

In the the Zip_AddItem method Lines 103 and 105 are original from the Zip UDF. It seems Zip_ItemExists is called and it is returning a zip file not found which causes the error 7. When I inserted line 104 below I see error 4 from Zip_ItemExists but the error 7 is not being set any longer and the subdirectory is being created. I don't understand why inserting a ConsoleWrite changes the outcome of execution? What is the solution for this error condition.

103 Local $itemExists = _Zip_ItemExists($sTest, $sNameOnly)

104 ConsoleWrite("err&ext: " & @error & " " & @extended & @CRLF)

105 If @error Then Return SetError(7, 0, 0)

Here are the lines from Zip_ItemExists which seems to be returning the error 4. Why is the zip file not found? Why is is being tested for an internal directory being created?

324 Local $oNS = $oApp.NameSpace($sZipFile)

325 If Not IsObj($oNS) Then Return SetError(4, 0, 0)

Any help is appreciated to correct this issue.

Rob

Edited by RobK
Link to comment
Share on other sites

I can tell you why the @error changes when you insert the ConsoleWrite line, @error will only contain the error of the previous statement that was run. In this case it's giving you the @error condition of the ConsoleWrite command. When you read the @error value is extremely important if you want to make sure you're reading it correctly and for the correct command. This has tripped up many a script because of where in the code the error checking was done.

Because the ConsoleWrite command doesn't set the @error macro, line 105 isn't executed any longer and the script continues after it. As to why you're getting the error in the Zip.udf I can't say because I haven't looked at it, but I thought I'd help out by explaining what you were seeing as far as the error messages were concerned. :x

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@RobK

Post full working code that exhibits your error. I'm going to guess you're not passing full paths to the source file and destination zip, as required in the function header.

Wraithdu,

I'm having the same problem as RobK. Even with your test code that you posted earlier in the topic. :x

Fran

#NoTrayIcon
;~ #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <_Zip.au3>

; create a test directory
$dir = @DesktopDir & "\mydir"
DirCreate($dir)
; create some files
For $i = 1 To 3
    FileWrite($dir & "\file" & $i, "")
Next
; create the ZIP
$file = _Zip_Create(@DesktopDir & "\test.zip", 1)
ConsoleWrite("err: " & @error & @CRLF)
_Zip_AddItem($file, $dir)
ConsoleWrite("err: " & @error & @CRLF)
; add it to a subdir
_Zip_AddItem($file, $dir, "dir1\dir2")
ConsoleWrite("err: " & @error & @CRLF)
; remove dir
DirRemove($dir, 1)

err: 0

err: 0

err: 7

Edited by Fran
Link to comment
Share on other sites

Ok, bug fixed. Damn, don't know when that one creeped in there. Please test functions again in general to make sure I didn't break something else please. I tested too, but more eyes is better. I modified only the AddItem and ItemExists functions, so impact should be limited to those functions.

Edited by wraithdu
Link to comment
Share on other sites

  • 1 month later...

I love the UDF! One thing though, using flag 8 in _Zip_AddItem "Rename the file if a file of the same name already exists" doesn't seem to work at all. It simply deletes the pre-existing file within the zip and then adds the new file without renaming it. There are no errors, the code I'm using is below (variables have been replaced with their values).

_Zip_AddItem("C:\Test\072006.zip","C:\Test\drivers\R205648\Lang\HDMI\ENU\license.txt","",28) ;Flag is 4+8+16

To be honest I can't even tell by looking at the function code where it attempts to rename the file, or what it would rename the file to. :) But I am by no means an AutoIT guru...

Using WinXP Pro SP3 and AutoIT v3.3.6.1

Edited by Gorby7
Link to comment
Share on other sites

Well for some reason I'm not allowed to edit my previous post again, but I entered the wrong code it should be:

_Zip_AddItem("C:\Dump\072006.zip","C:\Test\drivers\R205648\Lang\HDMI\ENU\license.txt","",28) ;Flag is 4+8+16
Edited by Gorby7
Link to comment
Share on other sites

I'm still curious as to why it didn't work originally, but I added some code to the function and it works now. If the file already exists in the archive it will be renamed from "filename.ext" to "filename(2).ext" before being placed in the archive. This works no matter how many instances of the same filename are found.

Func _Zip_AddItem($sZipFile, $sFileName, $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($sFileName) Then Return SetError(4, 0, 0)
    If Not FileExists($sFileName) Then Return SetError(5, 0, 0)
    If _IsFullPath($sDestDir) Then Return SetError(6, 0, 0)
    ; if file exists in archive then rename it first
    $cutp=StringInStr($sFileName,"\",0,-1)
    $fname=StringTrimLeft($sFileName,$cutp)
    While _Zip_ItemExists($sZipFile,$fname)
        $cutp=StringInStr($sFileName,"\",0,-1)
        $fname=StringTrimLeft($sFileName,$cutp)
        $path=StringTrimRight($sFileName,StringLen($sFileName)-$cutp)
        $fname1=StringTrimRight($fname,(StringLen($fname)-StringInStr($fname,".",0))+1)
        $exten=StringTrimLeft($fname,StringInStr($fname,".",0)-1)
        FileMove($sFileName,$path & $fname1 & "(2)" & $exten)
        $sFileName=$path & $fname1 & "(2)" & $exten
        $fname=$fname1 & "(2)" & $exten
    WEnd
    ; clean paths
    $sFileName = _Zip_PathStripSlash($sFileName)
    $sDestDir = _Zip_PathStripSlash($sDestDir)
    Local $sNameOnly = _Zip_PathNameOnly($sFileName)
    ; 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)
        $sZipFile &= "\" & $sDestDir
    EndIf
    Local $oApp = ObjCreate("Shell.Application")
    Local $oNS = $oApp.NameSpace($sZipFile)
    ; copy the file
    $oNS.CopyHere($sFileName, $iFlag)
    Do
        Sleep(250)
        $oItem = $oNS.ParseName($sNameOnly)
    Until IsObj($oItem)
    If $sTempFile <> "" Then _Zip_InternalDelete($sZipFile, $sTempFile)
    Return 1
EndFunc   ;==>_Zip_AddItem
Link to comment
Share on other sites

Well the flags control the shell object that actually moves the files. What happens when moving a single file, the function itself will delete the file before adding the new one so the shell object never sees it. You've worked around it for your circumstance. You could just as well remove the check for the existence of the destination item and see how the shell itself handles it.

Link to comment
Share on other sites

Well the flags control the shell object that actually moves the files. What happens when moving a single file, the function itself will delete the file before adding the new one so the shell object never sees it. You've worked around it for your circumstance. You could just as well remove the check for the existence of the destination item and see how the shell itself handles it.

I wish I knew a bit more about programming Posted Image, I still don't get it... are you saying that if the flags don't work correctly, it's because there's a problem with some of my Windows system files? Such as zipfldr.dll?

Link to comment
Share on other sites

Hmm it's still the same result, the existing file in the archive is deleted and the new one is placed into it with the original name. I commented out lines as below:

Func _Zip_AddItem($sZipFile, $sFileName, $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($sFileName) Then Return SetError(4, 0, 0)
    If Not FileExists($sFileName) Then Return SetError(5, 0, 0)
    If _IsFullPath($sDestDir) Then Return SetError(6, 0, 0)
    ; clean paths
    $sFileName = _Zip_PathStripSlash($sFileName)
    $sDestDir = _Zip_PathStripSlash($sDestDir)
    Local $sNameOnly = _Zip_PathNameOnly($sFileName)
    ; 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
                Sleep(1)
    ;_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)
        $sZipFile &= "\" & $sDestDir
    EndIf
    Local $oApp = ObjCreate("Shell.Application")
    Local $oNS = $oApp.NameSpace($sZipFile)
    ; copy the file
    $oNS.CopyHere($sFileName, $iFlag)
    Do
        Sleep(250)
        $oItem = $oNS.ParseName($sNameOnly)
    Until IsObj($oItem)
    ;If $sTempFile <> "" Then _Zip_InternalDelete($sZipFile, $sTempFile)
    Return 1
EndFunc   ;==>_Zip_AddItem

I also tried running it without the '16' flag, "Respond Yes to All for any dialog that is displayed", and still no luck. I'm not too worried about it at this point since my program is working, but like you said it won't work for other situations so I may be back someday.

Link to comment
Share on other sites

Yep, I see the issue. Unfortunately I can't always tell the shell what to do. There's two things at play here. One, the shell object, and two, the zipfldr library. There's nothing that says the zipfldr library needs to follow all the rules of the shell object. It's likely that some of the shell flags just do not work on zip files. For example, if you open a zip file with windows explorer (which uses the zipfldr library obviously) you'll notice there is no right-click option for rename. That says to me that this flag will never work for zip files, so you'll have to code a manual solution like your existing one.

Link to comment
Share on other sites

  • 1 month later...

Hello, i used the Zip list command but it didn't show me the name of the file inside the zip file. It has only one, could you tell me why it dosen't work? or were did i made the mistake?

thank you

#include <Zip.au3>
#include <Array.au3>
Local $Array[2]

;$x = _Zip_SearchInFile("c:\Rimlogs\1057886743-2011-03-30 T03-11-35.zip", "<idValue>1057886743</idValue>")
$Array[0] = _Zip_List("c:\Rimlogs\1057886743-2011-03-30 T03-11-35.zip")

If @error Then
    MsgBox(0,"Nu a mers",@error)
EndIf

$Array[1] = MsgBox(0,"A Mers",$Array[0])
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...