Windows API to extract zip files?

In Windows Explorer, you can extract the compressed folder (zip file)

Is there an API or command line to extract the zip file using the same method programmatically?

+5
source share
4 answers
+2
source

You can use this VBScript script:

'Adapted from http://www.robvanderwoude.com/vbstech_files_zip.html

strFile = "c:\filename.zip"
strDest = "c:\files"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If Not objFSO.FolderExists(strDest) Then
    objFSO.CreateFolder(strDest)
End If

UnZipFile strFile, strDest

Sub UnZipFile(strArchive, strDest)
    Set objApp = CreateObject( "Shell.Application" )

    Set objArchive = objApp.NameSpace(strArchive).Items()
    Set objDest = objApp.NameSpace(strDest)

    objDest.CopyHere objArchive
End Sub
+5
source

Sub UnZipFile(...) Excel 2010 : '91' ( )

Set objArchive = objApp.Namespace(strArchive).Items() 

Set objDest = objApp.Namespace(strDest)

: objDest !

Microsoft .Namespace() , , . , :

Set objArchive = objApp.Namespace(**CStr(** strArchive **)**).Items()  
Set objDest = objApp.Namespace(**CStr(** strDest **)**)

Set objArchive = objApp.Namespace(**"" &** strArchive).Items()  
Set objDest = objApp.Namespace(**"" &** strDest)

objDest.CopyHere objArchive : !

, Excel 2010 , , :

Sub UnZipFile(strZipArchive As String, strDestFolder As String)
  Dim objApp As Object
  Dim vItem As Variant
  Dim objDest As Object

  Set objApp = CreateObject("Shell.Application")
  Set objDest = objApp.Namespace(CStr(strDestFolder))
  For Each vItem In objApp.Namespace(CStr(strZipArchive)).Items
    objDest.CopyHere vItem
  Next vItem
End Sub
0

# VB MSDN: https://msdn.microsoft.com/en-us/library/ms404280(v=vs.100).aspx

.net 4.x, MSDN

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string startPath = @"c:\example\start";
            string zipPath = @"c:\example\result.zip";
            string extractPath = @"c:\example\extract";

            ZipFile.CreateFromDirectory(startPath, zipPath);

            ZipFile.ExtractToDirectory(zipPath, extractPath);
        }
    }
}
0

All Articles