IronFine Posted 8 hours ago Posted 8 hours ago (edited) Hello, based on this post, I am trying to use the method OpenRead with CLR to get a list if all files in a zip-archive: On 12/3/2017 at 8:16 PM, Danyfirex said: Hello. I was needing to zip and unzip some folders. So I found an easy way using CLR. here a simple example. #include ".\Includes\CLR.au3" #include ".\Includes\CLR Constants.au3" Local $oAssembly = _CLR_LoadLibrary("System.IO.Compression.FileSystem") ConsoleWrite("!$oAssembly: " & IsObj($oAssembly) & @CRLF) Local $pAssemblyType = 0 $oAssembly.GetType_2("System.IO.Compression.ZipFile", $pAssemblyType) ConsoleWrite("$pAssemblyType = " & Ptr($pAssemblyType) & @CRLF) Local $oAssemblyType = ObjCreateInterface($pAssemblyType, $sIID_IType, $sTag_IType) ConsoleWrite("IsObj( $oAssemblyType ) = " & IsObj($oAssemblyType) & @CRLF) Local $sInputFolder="C:\Users\Raziel\Desktop\Files" Local $sOutZipFile="C:\Users\Raziel\Desktop\Files.zip" Local $aArray[] = [$sInputFolder,$sOutZipFile] Local $Return = 0 ;compress $oAssemblyType.InvokeMember_3("CreateFromDirectory", 0x158, 0, 0, CreateSafeArray($aArray), $Return) Local $aArray[] = [$sOutZipFile,$sInputFolder & "-Extracted"] ;decompress $oAssemblyType.InvokeMember_3("ExtractToDirectory", 0x158, 0, 0, CreateSafeArray($aArray), $Return) Exit Saludos I have a working example in C# using System.IO.Compression; class Program { static void Main() { string zipPath = @"C:\Users\User\Desktop\Example.zip"; using (ZipArchive archive = ZipFile.OpenRead(zipPath)) { Console.WriteLine("Content of zip file:"); foreach (ZipArchiveEntry entry in archive.Entries) { Console.WriteLine($"- {entry.FullName} ({entry.Length} Bytes) {entry.LastWriteTime}"); } } } } IT seems that I am able to open the ZIP file, but I am not sure how access the Entries: #include ".\Includes\CLR.au3" #include ".\Includes\CLR Constants.au3" _Test("C:\Users\User\Desktop\Example.zip") Func _Test($zipFile) Local $oAssembly = _CLR_LoadLibrary("System.IO.Compression.ZipFile") ConsoleWrite("IsObj($oAssembly) = " & IsObj($oAssembly) & @CRLF) Local $pAssemblyType = 0 $oAssembly.GetType_2("System.IO.Compression.ZipFile", $pAssemblyType) ConsoleWrite("Ptr($pAssemblyType) = " & Ptr($pAssemblyType) & @CRLF) Local $oAssemblyType = ObjCreateInterface($pAssemblyType, $sIID_IType, $sTag_IType) ConsoleWrite("IsObj($oAssemblyType) = " & IsObj($oAssemblyType) & @CRLF) Local $aArray[1] = [$zipFile] Local $oReturn = 0 $oAssemblyType.InvokeMember_3("OpenRead", 0x158, 0, 0, CreateSafeArray($aArray), $oReturn) ConsoleWrite("IsObj($oReturn) = " & IsObj($oReturn) & @CRLF) Local $oEntries = $oReturn.Entries ConsoleWrite("IsObj($oEntries) = " & IsObj($oEntries) & @CRLF) ; I am at at loss here $oReturn.Dispose() ConsoleWrite("Done!" & @CRLF) EndFunc ;==>_Test Edited 8 hours ago by IronFine
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now