Jump to content

[s]Unzipping[/s] Zipping


Recommended Posts

So, is there still a question open?

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

I don't believe win2k server has a native zip utility in the OS ... is there a way to have this process execute in AIT?

I'd like to open the file, extract on the .xml inside of it (ignore the other file types) and then close the file and leave it where it was so that I can work with the extracted xml file

This uses COM to ask the built in windows unzipper to unzip the file

But how do I zip a file?

Link to comment
Share on other sites

Got it working :) thanks trance, great function!

The question is, will this work on server 2000? Do I need to include a file if not?

#Include <File.au3> 



; Tab 1 Modules


;~ DirCreate(@DesktopDir & "\Extracted") ; to extract to

$sPath = "D:\test"
$zipfilelist = _FileListToArray($sPath,"*.zip",1)
;~ MsgBox(0, "File List", $zipfilelist[1] & $zipfilelist[2] & $zipfilelist[3] & $zipfilelist[4] & $zipfilelist[5] & $zipfilelist[6] & $zipfilelist[7] & $zipfilelist[8] & $zipfilelist[9] & $zipfilelist[10] & $zipfilelist[11])



for $i = 1 to $zipfilelist[0] Step 1
;~  MsgBox(0, "$i", $zipfilelist[$i])
    Local $xmlname1
    Local $xmlname2
    
    $xmlname1 = StringReplace($zipfilelist[$i], ".", "")
;~  MsgBox(0,"xmlname1",$xmlname1)
    $xmlname2 = StringReplace($xmlname1, "zip", ".xml")
;~  MsgBox(0,"xmlname2",$xmlname2)
;~  MsgBox(0, "extract", "_ExtractZip(D:\dma\fecs\downloadbak\test\" & $zipfilelist[$i] )
    _ExtractZip("D:\test\" & $zipfilelist[$i] , "", $xmlname2, "C:\temp\testxmls")
;~  _ExtractZip(@DesktopDir & "\YourZipFile.zip", "SomeFolderWithinOrNothing", "FileOrFolderToExtract.extensionIfEny", @DesktopDir & "\Extracted")

;~  MsgBox(0,0,"END")

Next

ConsoleWrite(@error & @CRLF)




; #FUNCTION# ;===============================================================================
;
; Name...........: _ExtractZip
; Description ...: Extracts file/folder from ZIP compressed file
; Syntax.........: _ExtractZip($sZipFile, $sFolderStructure, $sFile, $sDestinationFolder)
; Parameters ....: $sZipFile - full path to the ZIP file to process
;                  $sFolderStructure - 'path' to the file/folder to extract inside ZIP file
;                  $sFile - file/folder to extract
;                  $sDestinationFolder - folder to extract to. Must exist.
; Return values .: Success - Returns 1
;                          - Sets @error to 0
;                  Failure - Returns 0 sets @error:
;                  |1 - Shell Object creation failure
;                  |2 - Destination folder is unavailable
;                  |3 - Structure within ZIP file is wrong
;                  |4 - Specified file/folder to extract not existing
; Author ........: trancexx
;
;==========================================================================================
Func _ExtractZip($sZipFile, $sFolderStructure, $sFile, $sDestinationFolder)

    Local $i
    Do
        $i += 1
        $sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
    Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction

    Local $oShell = ObjCreate("Shell.Application")

    If Not IsObj($oShell) Then
        Return SetError(1, 0, 0) ; highly unlikely but could happen
    EndIf

    Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
    If Not IsObj($oDestinationFolder) Then
        Return SetError(2, 0, 0) ; unavailable destionation location
    EndIf

    Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
    If Not IsObj($oOriginFolder) Then
        Return SetError(3, 0, 0) ; unavailable location
    EndIf

    ;Local $oOriginFile = $oOriginFolder.Items.Item($sFile)
    Local $oOriginFile = $oOriginFolder.ParseName($sFile)
    If Not IsObj($oOriginFile) Then
        Return SetError(4, 0, 0) ; no such file in ZIP file
    EndIf

    ; copy content of origin to destination
    $oDestinationFolder.CopyHere($oOriginFile, 4) ; 4 means "do not display a progress dialog box", but apparently doesn't work

    DirRemove($sTempZipFolder, 1) ; clean temp dir

    Return 1 ; All OK!

EndFunc
Link to comment
Share on other sites

Windows 2000 didn't get the "compressed folders" feature for some weird reason, but you can install the files from Win98/ME and it should work (never tried it myself). See guide HERE

Link to comment
Share on other sites

Thanks Admiral

It does not work, I see the tutorial was written in 2009, but the files it suggests are not available, I could only find the XP sp2 version of the kb329048, so I can't even get the files to try.

I checked the dlldump site and tried to use those, and that did not work.

If anyone has any ideas on how to make this work, I've put tons of time into this app, and without this function it's pretty much worthless.

Windows 2000 didn't get the "compressed folders" feature for some weird reason, but you can install the files from Win98/ME and it should work (never tried it myself). See guide HERE

Link to comment
Share on other sites

I was able to register these and have the extract function in the windows right click menu

This function now fails at this line ... help? Do I need to start a separate thread for this?

Local $oOriginFile = $oOriginFolder.ParseName($sFile) ; fails here

$oOriginFolder is blank

$sFile has an xml value name

I ran this on XP and $oOriginFolder was also blank there?

Error message is still

Posted Image

#Include <File.au3> 



; Tab 1 Modules


;~ DirCreate(@DesktopDir & "\Extracted") ; to extract to

$sPath = "D:\test"
$zipfilelist = _FileListToArray($sPath,"*.zip",1)
;~ MsgBox(0, "File List", $zipfilelist[1] & $zipfilelist[2] & $zipfilelist[3] & $zipfilelist[4] & $zipfilelist[5] & $zipfilelist[6] & $zipfilelist[7] & $zipfilelist[8] & $zipfilelist[9] & $zipfilelist[10] & $zipfilelist[11])



for $i = 1 to $zipfilelist[0] Step 1
;~  MsgBox(0, "$i", $zipfilelist[$i])
    Local $xmlname1
    Local $xmlname2
    
    $xmlname1 = StringReplace($zipfilelist[$i], ".", "")
;~  MsgBox(0,"xmlname1",$xmlname1)
    $xmlname2 = StringReplace($xmlname1, "zip", ".xml")
;~  MsgBox(0,"xmlname2",$xmlname2)
;~  MsgBox(0, "extract", "_ExtractZip(D:\dma\fecs\downloadbak\test\" & $zipfilelist[$i] )
    _ExtractZip("D:\test\" & $zipfilelist[$i] , "", $xmlname2, "C:\temp\testxmls")
;~  _ExtractZip(@DesktopDir & "\YourZipFile.zip", "SomeFolderWithinOrNothing", "FileOrFolderToExtract.extensionIfEny", @DesktopDir & "\Extracted")

;~  MsgBox(0,0,"END")

Next

ConsoleWrite(@error & @CRLF)




; #FUNCTION# ;===============================================================================
;
; Name...........: _ExtractZip
; Description ...: Extracts file/folder from ZIP compressed file
; Syntax.........: _ExtractZip($sZipFile, $sFolderStructure, $sFile, $sDestinationFolder)
; Parameters ....: $sZipFile - full path to the ZIP file to process
;                  $sFolderStructure - 'path' to the file/folder to extract inside ZIP file
;                  $sFile - file/folder to extract
;                  $sDestinationFolder - folder to extract to. Must exist.
; Return values .: Success - Returns 1
;                          - Sets @error to 0
;                  Failure - Returns 0 sets @error:
;                  |1 - Shell Object creation failure
;                  |2 - Destination folder is unavailable
;                  |3 - Structure within ZIP file is wrong
;                  |4 - Specified file/folder to extract not existing
; Author ........: trancexx
;
;==========================================================================================
Func _ExtractZip($sZipFile, $sFolderStructure, $sFile, $sDestinationFolder)

    Local $i
    Do
        $i += 1
        $sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
    Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction

    Local $oShell = ObjCreate("Shell.Application")

    If Not IsObj($oShell) Then
        Return SetError(1, 0, 0) ; highly unlikely but could happen
    EndIf

    Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
    If Not IsObj($oDestinationFolder) Then
        Return SetError(2, 0, 0) ; unavailable destionation location
    EndIf

    Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
    If Not IsObj($oOriginFolder) Then
        Return SetError(3, 0, 0) ; unavailable location
    EndIf

    ;Local $oOriginFile = $oOriginFolder.Items.Item($sFile)
    Local $oOriginFile = $oOriginFolder.ParseName($sFile)
    If Not IsObj($oOriginFile) Then
        Return SetError(4, 0, 0) ; no such file in ZIP file
    EndIf

    ; copy content of origin to destination
    $oDestinationFolder.CopyHere($oOriginFile, 4) ; 4 means "do not display a progress dialog box", but apparently doesn't work

    DirRemove($sTempZipFolder, 1) ; clean temp dir

    Return 1 ; All OK!

EndFunc

I found this tonight

http://download.microsoft.com/download/Win98/UPDATE/25556/W98/EN-US/329048USA8.EXE

I'll have to try it tomorrow

Maybe someone has this patch/files referenced in the link Admiral posted on an old winME disc?

Link to comment
Share on other sites

Maybe the zip file is in a format that Windows can't handle? (I have no Win2000 to test with).

Have you thought about going an alternative way, maybe something like 7Zip UDF? (just an idea, I never used it myself so don't know if it is any good)

Link to comment
Share on other sites

Here's the thing.

You obviously can't copy zipfldr.dll from XP (or whatever) to win2k for it to work properly.

Your attempt to register it Run("regsvr32.exe zipfldr.dll") fails. It's failing because zipfldr.dll have imported functions from other dlls that are not found on win2k. To find which one for start run

DllOpen("zipfldr.dll")

That doesn't mean it can't be used, just requires additional work. That of course also means that it may just not work at all :) .

Post the error message you get when you run suggested code on win2k.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

The error message my program gives is the following

Posted Image

I'm not sure what you are looking for with the dllopen, but I ran this code and $dllinfo = 1 and $result = 0

$dllinfo = DllOpen("c:\winnt\system32\zipfldr.dll")
$result = DllCall($dllinfo, "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0)
MsgBox(0, 0, $dllinfo)
MsgBox(0, 0, $result)

Here's the thing.

You obviously can't copy zipfldr.dll from XP (or whatever) to win2k for it to work properly.

Your attempt to register it Run("regsvr32.exe zipfldr.dll") fails. It's failing because zipfldr.dll have imported functions from other dlls that are not found on win2k. To find which one for start run

DllOpen("zipfldr.dll")

That doesn't mean it can't be used, just requires additional work. That of course also means that it may just not work at all :) .

Post the error message you get when you run suggested code on win2k.

Link to comment
Share on other sites

The error message my program gives is the following

Posted Image

I'm not sure what you are looking for with the dllopen, but I ran this code and $dllinfo = 1 and $result = 0

$dllinfo = DllOpen("c:\winnt\system32\zipfldr.dll")
$result = DllCall($dllinfo, "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0)
MsgBox(0, 0, $dllinfo)
MsgBox(0, 0, $result)

I didn't ask that. Run this on win2k. And don't change anything:

RunWait("regsvr32.exe zipfldr.dll")
MsgBox(0,'DllOpen',DllOpen("zipfldr.dll"))

Show what you get.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

DllCall returns an array, you can't check it like that!

$result = DllCall($dllinfo, "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0)
_ArrayDisplay($result)

But I don't think that was what trancexx meant.... :)

Edit: yep I was right ;)

Edited by AdmiralAlkex
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...