SevenZip

SevenZip is an included compression module that can pack and unpack many supported methods: 7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM.
Further it can unpack AR, ARJ, CAB, CHM, CPIO, CramFS, DMG, EXT, FAT, GPT, HFS, IHEX, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, QCOW2, RAR, RPM, SquashFS, UDF, UEFI, VDI, VHD, VMDK, WIM, XAR and Z.
It can also create a self extracting executable.

7-zip was created by Igor Pavlov - www.7-zip.org.
Dll version was compiled from https://github.com/ytakanashi/7-zip32_ungarbled.

SevenZip() loads the dll module from resources and return an object with methods.

OutputVar := SevenZip(Hwnd)
OutputVar

The name of variable in which to store the object that will be used for compression, decompression and other 7-zip functions.

Hwnd (optional)

Gui hwnd to disable interaction with it while zip is performing compression or decompression..

Properties

Methods

Add

Add file[s] to archive, if archive does not exist, it will be created.

OutputVar := zip.Add(Archive, Files, Options)
OutputVar

The name of variable in which to store the result reported by 7-zip.

Archive

Archive file name or path where file[s] will be added to.

Files

One or multiple files, path or file pattern that will be added to archive.
When multiple files are passed, they need to be separated by new line, e.g. "C:\File1.txt`nC:\File`nC:\MyDir"

Options (optional)

See supported switches in 7-zip Add() help.

AutoZip

Automated method to add file[s] to archive
If archive already exists it will be re-compressed (extracted, deleted and compressed) with given options, it will be also converted if a different method is used, original archive will be deleted!
If file or path is not an archive or a folder, it will be compressed using same path/name appending method as extension.

OutputVar := zip.AutoZip(Archive, Method, CompressionLevel, Threads, Options)
OutputVar

The name of variable in which to store the result reported by 7-zip.

Archive

File name or path of existing archive, file or folder to compress.

Method (optional)

One of supported methods. The name will also be used for new file extension.
Default: zip.

CompressionLevel (optional)

Compression level 0,1,3,5,7,9 for new archive, see list of supported compression level.
Default: level 9 for maximum compression.

Threads (optional)

How many threads to use for compression.
Default: 2 threads.

Options (optional)

Additional options valid for Add command.

Check

Checks if file is an archive file (check header) and optionally checking the content and CRC for each file.

OutputVar := zip.Check(Archive, Mode)
OutputVar

The name of variable in which to store true / 1 if file is an archive and false / 0 if file is not an archive or archive is corrupted.

Archive

File name or path of existing archive.

Mode (optional)

Checking mode:

  • 0: check header only.
  • 1: check additionally if archive is corrupted.
  • 2: check additionally CRC for all files in archive.

Default: 0.

ClearOwnerWindow

Disable messages to previously defined window by SetOwnerWindow.

OutputVar := zip.ClearOwnerWindow()
OutputVar

The name of variable in which to store true / 1 on success and false / 0 if no window is set up to receive messages.

Close

Close archive previously opened by Open.

OutputVar := zip.Check(ArchiveHandle)
OutputVar

The name of variable in which to store true / 1 if file is an archive and false / 0 if file is not an archive or archive is corrupted.

ArchiveHandle

Handle previously returned by Open.

Cmd

Run 7-zip command line, see Command line syntax.

OutputVar := zip.Cmd(CommandLine)
OutputVar

The name of variable in which to store the result reported by 7-zip.

CommandLine

All functions can be run via Command Line, see Command line syntax.

ConfigDialog

Shows version and copyright information.

zip.ConfigDialog()

Delete

Delete file[s] from archive.

OutputVar := zip.Delete(Archive, Files, Options)
OutputVar

The name of variable in which to store the result reported by 7-zip.

Archive

Archive file name or paths where file[s] will be deleted from.

Files

One or multiple files, path or file pattern that will be deleted from archive.
When multiple files are passed, they need to be separated by new line, e.g. "C:\File1.txt`nC:\File`nC:\MyDir"

Options (optional)

See supported switches in 7-zip Add() help.

Extract

Extract file[s] with full path[s] from archive.

OutputVar := zip.Extract(Archive, Dir, Files, Options)
OutputVar

The name of variable in which to store the result reported by 7-zip.

Archive

Archive file name or paths where file[s] will be extracted from.

Dir (optional)

Output directory.

Files (optional)

One or multiple files, path or file pattern that will be extracted from archive.
When multiple files are passed, they need to be separated by new line, e.g. "C:\File1.txt`nC:\File`nC:\MyDir"

Options (optional)

See supported switches in 7-zip Add() help.

ExtractMem

Extract file[s] with full path[s] from archive.
This command supports extracting files up to 4 GB, use ExtractMemEx for larger files.

OutputVar := zip.Extract(Buffer, Archive, File, Options)
OutputVar

The name of variable in which to store size of buffer (uncompressed file size).

Buffer

ByRef variable that will contain extracted data.

Archive

Archive file name or paths where file[s] will be extracted from.

File (optional)

File that will be extracted from archive.

Options (optional)

See supported switches in 7-zip Add() help.

ExtractMemEx

Extract file[s] with full path[s] from archive.

OutputVar := zip.Extract(Buffer, Archive, File, Options)
OutputVar

The name of variable in which to store size of buffer (uncompressed file size).

Buffer

ByRef variable that will contain extracted data.

Archive

Archive file name or paths where file[s] will be extracted from.

File (optional)

File that will be extracted from archive.

Options (optional)

See supported switches in 7-zip Add() help.

ExtractRoot

Extract file[s] with full path[s] from archive.

OutputVar := zip.ExtractRoot(Archive, Dir, Files, Options)
OutputVar

The name of variable in which to store the result reported by 7-zip.

Archive

Archive file name or paths where file[s] will be extracted from.

Dir (optional)

Output directory.

Files (optional)

One or multiple files, path or file pattern that will be extracted from archive.
When multiple files are passed, they need to be separated by new line, e.g. "C:\File1.txt`nC:\File`nC:\MyDir"

Options (optional)

See supported switches in 7-zip Add() help.

FindFirst

Find first file in archive, see also FindNext.

OutputVar := zip.FindFirst(ArchiveHandle, FilePattern)
OutputVar

The name of variable in which to store INDIVIDUALINFO structure.

typedef struct {
        DWORD dwOriginalSize;
        DWORD dwCompressedSize;
        DWORD dwCRC;
        UINT uFlag;
        UINT uOS Type;
        WORT wRatio;
        WORT wDate;
        WORT wTime;
        char szFileName [FNAME_MAX32 + 1];
        char dummy1 [3];
        char szAttribute [8];
        char szMode [8];
    } INDIVIDUALINFO;
  • dwOriginalSize: original file size.
  • dwCompressedSize: compressed file size.
  • dwCRC: file checksum.
  • uFlag: always 0.
  • uOSType: operation System, currently always 0.
  • wRatio: compression ratio. For solid archive always 0.
  • wDate: change time.
  • wTime: update time.
  • szFileName: file name.
  • szAttribute: File attributes.
  • szMode: compression method.

ArchiveHandle

Handle previously returned by Open.

FilePattern (optional)

File pattern to use for search, FindNext will continue using same file pattern.

FindNext

Find next file in archive.

OutputVar := zip.FindNext(ArchiveHandle, lpINDIVIDUALINFO)
OutputVar

The name of variable in which to store 0 on success or -1 if no more files could be found.

ArchiveHandle

Handle previously returned by Open.

lpINDIVIDUALINFO

Pointer to INDIVIDUALINFO structure to use for search.

GetArcAccessTimeEx

Get archive access time.

OutputVar := zip.GetArcAccessTimeEx(ArchiveHandle, lpFILETIME)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

ArchiveHandle

Handle previously returned by Open.

lpFILETIME

Pointer to FILETIME structure to receive the result. Pass getvar(time:=0) to save 64-bit value in variable.

GetArcCompressedSize

Get archive compressed size.

OutputVar := zip.GetArcCompressedSize(ArchiveHandle)
OutputVar

The name of variable in which to store compressed size or -1 if archive is solid archive or GetArcCompressedSizeEx needs to be used.

ArchiveHandle

Handle previously returned by Open.

GetArcCompressedSizeEx

Get archive compressed size.

OutputVar := zip.GetArcCompressedSizeEx(ArchiveHandle, lpINT64)
OutputVar

The name of variable in which to store true / 1 ono success or false / 0 on error.

ArchiveHandle

Handle previously returned by Open.

lpINT64

Pointer to variable to receive the compressed size. Pass getvar(size:=0) or pointer to buffer.

GetArcCreateTimeEx

Get archive created time.

OutputVar := zip.GetArcAccessTimeEx(ArchiveHandle, lpFILETIME)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

ArchiveHandle

Handle previously returned by Open.

lpFILETIME

Pointer to FILETIME structure to receive the result. Pass getvar(time:=0) to save 64-bit value in variable.

GetArcDate

Get archive date.

OutputVar := zip.GetArcDate(ArchiveHandle)
OutputVar

The name of variable in which to store archive date in DOS format or -1 on error.

ArchiveHandle

Handle previously returned by Open.

GetArcFileName

Get archive file name.

OutputVar := zip.GetArcDate(ArchiveHandle)
OutputVar

The name of variable in which to store archive file Name.

ArchiveHandle

Handle previously returned by Open.

GetArcFileSize

Get archive size.

OutputVar := zip.GetArcFileSize(ArchiveHandle)
OutputVar

The name of variable in which to store archive size or -1 on error.

ArchiveHandle

Handle previously returned by Open.

GetArcFileSizeEx

Get archive size.

OutputVar := zip.GetArcFileSizeEx(ArchiveHandle, lpINT64)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

ArchiveHandle

Handle previously returned by Open.

lpINT64

Pointer to buffer to get size. Use getvar(size:=0) or pass a buffer pointer.

GetArcOriginalSize

Get uncompressed archive size.

OutputVar := zip.GetArcOriginalSize(ArchiveHandle)
OutputVar

The name of variable in which to store archive size or -1 on error.

ArchiveHandle

Handle previously returned by Open.

GetArcOriginalSizeEx

Get uncompressed archive size.

OutputVar := zip.GetArcOriginalSizeEx(ArchiveHandle, lpINT64)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

ArchiveHandle

Handle previously returned by Open.

lpINT64

Pointer to buffer to get size. Use getvar(size:=0) or pass a buffer pointer.

GetArcOSType

Get uncompressed archive size.

OutputVar := zip.GetArcOSType(ArchiveHandle)
OutputVar

The name of variable in which to store OS type.

0 : MS-DOS  1 : PRIMOS  2 : UNIX    3 : AMIGA
4 : MAC-OS  5 : OS/2    6 : APPLE GS    7 : ATARI ST
8 : NEXT    9 : VAX VMS 10: In addition.
11: OS9     12: OS/68K  13: OS/386  14: HUMAN
15: CP/M    16: FLEX    17: Runser
18: VM CMS  19: Z SYSTEM    20: TOPS20  21: Windows NTFS
-1: Error.

ArchiveHandle

Handle previously returned by Open.

GetArcRatio

Get compression ratio for archive, 500 means 50% ratio.

OutputVar := zip.GetArcRatio(ArchiveHandle)
OutputVar

The name of variable in which to store compression ratio (0 for solid archive) or -1 on error.

ArchiveHandle

Handle previously returned by Open.

GetArcTime

Get archive time in DOS format.

OutputVar := zip.GetArcTime(ArchiveHandle)
OutputVar

The name of variable in which to store archive time in MSDOS format or -1 on error.

ArchiveHandle

Handle previously returned by Open.

GetArcWriteTimeEx

Get archive change time.

OutputVar := zip.GetArcWriteTimeEx(ArchiveHandle, lpFILETIME)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

ArchiveHandle

Handle previously returned by Open.

lpFILETIME

Pointer to FILETIME structure to receive the time. Pass getvar(time:=0) to save 64-bit value in variable.

GetAttribute

Get current file attribute, found by FindFirst or FindNext.

OutputVar := zip.GetAttribute(ArchiveHandle)
OutputVar

The name of variable in which to store archive attribute or -1 on error.

    0x01    FA_RDONLY       Reading only file.
    0x02    FA_HIDDEN       Hidden file.
    0x04    FA_SYSTEM       System file.
    0x08    FA_LABEL        Volume label.
    0x10    FA_DIREC        Directory.
    0x20    FA_ARCH         Retention bit.
    0x40    FA_ENCRYPTED    The file is password protected.

ArchiveHandle

Handle previously returned by Open.

GetBackGroundMode

Check if 7-zip is in background mode.

OutputVar := zip.GetBackGroundMode()
OutputVar

The name of variable in which to store true / 1 if 7-zip is in background mode false / 0 otherwise.

GetCompressedSize

Get compressed size for current file, found by FindFirst or FindNext.

OutputVar := zip.GetCompressedSize(ArchiveHandle)
OutputVar

The name of variable in which to store compressed file size or -1 on error.

ArchiveHandle

Handle previously returned by Open.

GetCompressedSizeEx

Get compressed size for current file, found by FindFirst or FindNext.

OutputVar := zip.GetArcWriteTimeEx(ArchiveHandle, lpINT64)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

ArchiveHandle

Handle previously returned by Open.

lpINT64

Pointer to buffer to receive the compressed size. Pass getvar(size:=0) to save 64-bit value in variable.

GetCRC

Get CRC for current file, found by FindFirst or FindNext.

OutputVar := zip.GetCRC(ArchiveHandle)
OutputVar

The name of variable in which to store code page identifier.

ArchiveHandle

Handle previously returned by Open.

GetCP

Get code page identifier.

OutputVar := zip.GetCP()
OutputVar

The name of variable in which to store code page identifier.

GetCursorInterval

Get rotary speed of cursor.

OutputVar := zip.GetCursorInterval()
OutputVar

The name of variable in which to store the speed of cursor.

GetCursorMode

Check if cursor will be visible in 7-zip operation.

OutputVar := zip.GetCursorMode()
OutputVar

The name of variable in which to store true / 1 if visible or false / 0 if hidden.

GetDate

Get date for current file, found by FindFirst or FindNext.

OutputVar := zip.GetDate(ArchiveHandle)
OutputVar

The name of variable in which to store the date in MSDOS format.

ArchiveHandle

Handle previously returned by Open.

GetDefaultPassword

Get default password that is used if archive is password protected and no password was specified.

OutputVar := zip.GetDefaultPassword(ArchiveHandle)
OutputVar

The name of variable in which to store the password.

ArchiveHandle (optional)

Handle previously returned by Open.
When no handle is given, global password is returned.

GetFileCount

Get count of files in an archive.

OutputVar := zip.GetFileCount(Archive)
OutputVar

The name of variable in which to store the count of files in archive.

Archive

Filename or path to an archive.

GetFileName

Get file name for current file, found by FindFirst or FindNext.

OutputVar := zip.GetFileName(ArchiveHandle)
OutputVar

The name of variable in which to store the file name.

ArchiveHandle

Handle previously returned by Open.
When no handle is given, global password is returned.

GetLastError

Get file name for current file, found by FindFirst or FindNext.

OutputVar := zip.GetLastError(lpINT)
OutputVar

The name of variable in which to store the error code.

lpINT (optional)

Pointer to buffer to save error code. Use getvar(err:=0) to save the code in a variable.

GetMethod

Get compression method name for current file, found by FindFirst or FindNext.

OutputVar := zip.GetMethod(ArchiveHandle)
OutputVar

The name of variable in which to store the compression method.

ArchiveHandle

Handle previously returned by Open.
When no handle is given, global password is returned.

GetOriginalSize

Get uncompressed size for current file, found by FindFirst or FindNext.

OutputVar := zip.GetOriginalSize(ArchiveHandle)
OutputVar

The name of variable in which to store uncompressed file size or -1 on error.

ArchiveHandle

Handle previously returned by Open.

GetOriginalSizeEx

Get uncompressed size for current file, found by FindFirst or FindNext.

OutputVar := zip.GetOriginalSizeEx(ArchiveHandle, lpINT64)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

ArchiveHandle

Handle previously returned by Open.

lpINT64

Pointer to buffer to receive the uncompressed size. Use getvar(size:=0) to save 64-bit value in variable.

GetOSType

Get os type for current file, found by FindFirst or FindNext.
At the moment only 0 is returned unless there was an error.

OutputVar := zip.GetOSType(ArchiveHandle)
OutputVar

The name of variable in which to store 0 on success, any other value means error.

ArchiveHandle

Handle previously returned by Open.

GetRatio

Get compression ratio for current file, found by FindFirst or FindNext.
500 means 50% ratio.

OutputVar := zip.GetRatio(ArchiveHandle)
OutputVar

The name of variable in which to store compression ratio (0 for solid archive) or -1 on error.

ArchiveHandle

Handle previously returned by Open.

GetRunning

Check if 7-zip is currently in compression or decompression operation.

OutputVar := zip.GetRunning()
OutputVar

The name of variable in which to store true / 1 if 7-zip is currently in operation or false / 0 otherwise.

GetSubVersion

Get subversion of 7-zip. See also GetVersion for main version.

OutputVar := zip.GetSubVersion()
OutputVar

The name of variable in which to store the subversion of 7-zip module.

GetTime

Get time stamp for current file, found by FindFirst or FindNext.

OutputVar := zip.GetTime(ArchiveHandle)
OutputVar

The name of variable in which to store time stamp in MSDOS format or -1 on error.

ArchiveHandle

Handle previously returned by Open.

GetType

Get archive type for an archive.

OutputVar := zip.GetType(Archive)
OutputVar

The name of variable in which to store archive type or -1 on error.

Archive

File name or path of an archive.

GetVersion

Get main version of 7-zip. See also GetSubVersion for subversion.

OutputVar := zip.GetVersion()
OutputVar

The name of variable in which to store the main version of 7-zip module.

GetWriteTime

Get archive time in DOS format for current file, found by FindFirst or FindNext.

OutputVar := zip.GetWriteTime(ArchiveHandle)
OutputVar

The name of variable in which to store file time in MSDOS format or -1 on error.

ArchiveHandle

Handle previously returned by Open.

GetWriteTimeEx

Get archive time in DOS format for current file, found by FindFirst or FindNext.

OutputVar := zip.GetWriteTimeEx(ArchiveHandle, lpFILETIME)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

ArchiveHandle

Handle previously returned by Open.

lpFILETIME

Pointer to FILETIME structure to receive the time. Pass getvar(time:=0) to save 64-bit value in variable.

Hash

Create a Hash for file[s].

OutputVar := zip.Hash(CRC, Files, Options)
OutputVar

The name of variable in which to store the result reported by 7-zip.

CRC

CRC method. Supported methods: CRC32, CRC64, SHA1, SHA256, BLAKE2sp. Default method is CRC32

Files

One or multiple files, path or file pattern to calculate hash for.
When multiple files are passed, they need to be separated by new line, e.g. "C:\File1.txt`nC:\File`nC:\MyDir"

Options (optional)

See supported switches in 7-zip Add() help.

IsSFXFile

Check if archive is a self extracting archive. Currently only 0 is returned unless there is an error.

OutputVar := zip.IsSFXFile(ArchiveHandle)
OutputVar

The name of variable in which to store 0 or -1 on error.

ArchiveHandle

Handle previously returned by Open.

KillOwnerWindowEx

Stop watching for messages from 7-zip module. See SetOwnerWindowEx.

OutputVar := zip.KillOwnerWindowEx(WindowHandle)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 if handle does not match.

WindowHandle

Handle of the window currently watching for messages.

KillOwnerWindowEx64

Stop watching for messages from 7-zip module. See SetOwnerWindowEx64.

OutputVar := zip.KillOwnerWindowEx64(WindowHandle)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 if handle does not match.

WindowHandle

Handle of the window currently watching for messages.

List

List files and other information in the archive.

OutputVar := zip.List(Archive, FilePattern)
OutputVar

The name of variable in which to store an array, each element will contain an array with [Date, Time, File Attributes, Uncompressed size, Compressed size, FilePath].

FilePattern (optional)

File pattern to filter. See Wildcards.

Open

Open an archive.

OutputVar := zip.Open(Archive, Mode)
OutputVar

The name of variable in which to store the ArchiveHandle.

Archive

File name or path of an archive.

Mode (optional)

Following flags are supported:

  • M_ERROR_MESSAGE_ON (0x400000): Ask for a password for password protected archive, otherwise password set by SetDefaultPassword will be used.
  • M_CHECK_ALL_PATH (0x100): Enable recurse subdirectories for FindFirst
  • M_CHECK_FILENAME_ONLY (0x200): Disable recurse subdirectories. When M_CHECK_ALL_PATH | M_CHECK_FILENAME_ONLY is used, it will enable recurse subdirectories only for wildcard names.

PasswordDialog

Show password window and return entered password.

OutputVar := zip.PasswordDialog()
OutputVar

The name of variable in which to store the password.

Rename

Rename file[s] in archive.

OutputVar := zip.Update(Archive, Files, Options)
OutputVar

The name of variable in which to store the result reported by 7-zip.

Archive

Archive file name or path where file[s] will be updated.

Files

One or multiple pair of files or path (nameFrom nameTo) that will be renamed in archive.
Files need to be separated by new line, e.g. "File1.txt`nFile2`nMyDir\`nMyDir2\"

Options (optional)

See supported switches in 7-zip Add() help.

SetBackGroundMode

Set background mode for 7-zip. Currently the value is saved but not used internally.

OutputVar := zip.SetBackGroundMode(BackgroundMode)
OutputVar

The name of variable in which to store the background mode.

BackgroundMode

1 for background mode or 0 for non-background mode.

SetCP

Set code page of archive.

OutputVar := zip.SetCP(CodePage)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 if code page < 1.

CodePage

Code page used for Open.

SetCursorInterval

Set rotary speed of cursor.

OutputVar := zip.SetCursorInterval(Interval)
OutputVar

The name of variable in which to store true / 1.

Interval

Rotation speed of cursor in ms.

SetCursorMode

Set if cursor will be visible in 7-zip operation.

OutputVar := zip.SetCursorMode(CursorMode)
OutputVar

The name of variable in which to store true / 1.

CursorMode

True / 1 to show cursor, False / 0 to hide cursor.

SetDefaultPassword

Set default password that is used if archive is password protected and no password was specified.

OutputVar := zip.SetDefaultPassword(ArchiveHandle, Password)
OutputVar

The name of variable in which to store 0 on success, other values mean error.

ArchiveHandle (optional)

Handle previously returned by Open.
When no handle is given, global password is set.

Password (optional)

Password to use for further operations.

SetOwnerWindow

Set up messages for a window when 7-zip is in Compression or decompression operation. Use ClearOwnerWindow to stop watching for messages.
To watch for messages, call OnMessage with message nummber returned by wm_arcextract:=RegisterWindowMessage("wm_arcextract").

OutputVar := zip.SetOwnerWindow(WindowHandle)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

WindowHandle

Handle of the window that will receive messages from 7-zip module.

wParam will contain state of operation:
            0: BEGIN
            1: INPROCESS
            2: END
            3: OPEN
            4: COPY
            5: SKIP
lParam will contain a pointer to EXTRACTINGINFO Structure:
            typedef struct {
                    DWORD dwFileSize;                         // Total size of all data to be compressed / decompressed
                    DWORD dwWriteSize;                        // Processed size of all data to be compressed / decompressed
                    char szSourceFileName [FNAME_MAX32 + 1];  // Source file name (512 + 1)
                    char dummy1 [3];                          // padding
                    char szDestFileName [FNAME_MAX32 + 1];    // Destination file name (512 + 1)
                    char dummy [3];                           // padding
                } EXTRACTINGINFO;

SetOwnerWindowEx

Set up messages for a window when 7-zip is in Compression or decompression operation. Use KillOwnerWindowEx to stop watching for messages.
To watch for messages, call OnMessage with message nummber returned by wm_arcextract:=RegisterWindowMessage("wm_arcextract").

OutputVar := zip.SetOwnerWindowEx(WindowHandle, LPARCHIVERPROC)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

WindowHandle

Handle of the window that will receive messages from 7-zip module.

LPARCHIVERPROC (optinal)

Callback function created with RegisterCallback with following parameters:

  typedef BOOL CALLBACK ARCHIVERPROC(HWND _hwnd, UINT _uMsg,
                                     UINT _nState, LPVOID _lpEis);

  hwnd     Window handle.
  Msg     wm_arcextract.
  State   Operation mode.
            0: BEGIN
            1: INPROCESS
            2: END
            3: OPEN
            4: COPY
            5: SKIP
  pEIS    LPEXTRACTINGINFOEX
          typedef struct {
              EXTRACTINGINFO exinfo;  // EXTRACTINGINFO structure
              DWORD dwCompressedSize; // Compressed size
              DWORD dwCRC;            // CRC Checksum
              UINT uOS Type;          // Operation system
              WORD wRatio;            // compression ratio
              WORD wDate;             // change date in MSDOS format
              WORD wTime;             // change time in MSDOS format
              char szAttribute [8];   // file attributes
              char szMode [8];        // compression mode
          } EXTRACTINGINFOEX;

ARCHIVERPROC must return true to continue operation or false to cancel.

If LPARCHIVERPROC is omitted or 0, Window message mode will be used. (wParam = State, lParam = pEIS, hwnd, Msg)

SetOwnerWindowEx64

Set up messages for a window when 7-zip is in Compression or decompression operation. Use KillOwnerWindowEx64 to stop watching for messages.
To watch for messages, call OnMessage with message nummber returned by wm_arcextract:=RegisterWindowMessage("wm_arcextract").

OutputVar := zip.SetOwnerWindowEx64(WindowHandle, LPARCHIVERPROC, StructSize)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

WindowHandle

Handle of the window that will receive messages from 7-zip module.

LPARCHIVERPROC (optinal)

Callback function created with RegisterCallback with following parameters:

  typedef BOOL CALLBACK ARCHIVERPROC(HWND _hwnd, UINT _uMsg,
                                     UINT _nState, LPVOID _lpEis);

  hwnd     Window handle.
  Msg     wm_arcextract.
  State   Operation mode.
            0: BEGIN
            1: INPROCESS
            2: END
            3: OPEN
            4: COPY
            5: SKIP
  pEIS    LPEXTRACTINGINFO, LPEXTRACTINGINFOEX, LPEXTRACTINGINFOEX32 or LPEXTRACTINGINFOEX64
          typedef struct {
              DWORD dwStructSize;                       // Structure size
              EXTRACTINGINFO exinfo;                    // EXTRACTINGINFO structure
              DWORD dwFileSize;                         // Total size of all data to be compressed / decompressed
              DWORD dwCompressedSize;                   // Total size of compressed archive
              DWORD dwWriteSize;                        // Processed size of all data to be compressed / decompressed
              DWORD dwAttributes;                       // File attributes
              DWORD dwCRC;                              // CRC Checksum
              UINT uOS Type;                            // Operation system
              WORD wRatio;                              // compression ratio
              FILETIME ftCreateTime;                    // Created date and time
              FILETIME ftAccessTime;                    // Access date and time
              FILETIME ftWriteTime;                     // Chage date and time
              char szMode [8];                          // compression mode
              char szSourceFileName [FNAME_MAX32 + 1];  // Source file name (512 + 1)
              char dummy1 [3];                          // padding
              char szDestFileName [FNAME_MAX32 + 1];    // Destination file name (512 + 1)
              char dummy2 [3];                          // padding
          } EXTRACTINGINFOEX32;
          
          typedef struct {
              DWORD dwStructSize;                       // Structure size
              EXTRACTINGINFO exinfo;                    // EXTRACTINGINFO structure
              ULHA_INT64 llFileSize;                    // Total size of all data to be compressed / decompressed
              ULHA_INT64 llCompressedSize;              // Total size of compressed archive
              ULHA_INT64 llWriteSize;                   // Processed size of all data to be compressed / decompressed
              DWORD dwAttributes;                       // File attributes
              DWORD dwCRC;                              // CRC Checksum
              UINT uOS Type;                            // Operation system
              WORT wRatio;                              // compression ratio
              FILETIME ftCreateTime;                    // Created date and time
              FILETIME ftAccessTime;                    // Access date and time
              FILETIME ftWriteTime;                     // Chage date and time
              char szMode [8];                          // compression mode
              char szSourceFileName [FNAME_MAX32 + 1];  // Source file name (512 + 1)
              char dummy1 [3];                          // padding
              char szDestFileName [FNAME_MAX32 + 1];    // Destination file name (512 + 1)
              char dummy2 [3];                          // padding
          } EXTRACTINGINFOEX64;

ARCHIVERPROC must return true to continue operation or false to cancel.

If LPARCHIVERPROC is omitted or 0, Window message mode will be used. (wParam = State, lParam = pEIS, hwnd, Msg)

StructSize

The size of structure to use. Based on the size it will be either EXTRACTINGINFO, EXTRACTINGINFOEX, EXTRACTINGINFOEX32 or EXTRACTINGINFOEX64

SetPriority

Set thread priority.

OutputVar := zip.SetPriority(Priority)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

Priority

Use same values as in SetThreadPriority.

SetUnicodeMode

Set thread priority.

OutputVar := zip.SetUnicodeMode(UseUnicode)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

UseUnicode

True / 1 to use UTF-8 or false / 0 to use OEM code.

SfxConfigDialog

Shows Self Extracting dialog and returns entered values.

OutputVar := zip.SfxConfigDialog()
OutputVar

The name of variable in which to store entered values.

SfxFileStoring

Extract the executable used for Self Extracting archives.

OutputVar := zip.SfxFileStoring(FilePath)
OutputVar

The name of variable in which to store true / 1 on success or false / 0 on error.

FilePath

Path for SFX module to be extracted to.

Update

Update file[s] in archive.

OutputVar := zip.Update(Archive, Files, Options)
OutputVar

The name of variable in which to store the result reported by 7-zip.

Archive

Archive file name or path where file[s] will be updated.

Files

One or multiple files, path or file pattern that will be updated in archive.
When multiple files are passed, they need to be separated by new line, e.g. "C:\File1.txt`nC:\File`nC:\MyDir"

Options (optional)

See supported switches in 7-zip Add() help.

Test

Test archive or file[s] in archive.

OutputVar := zip.Test(Archive, Files, Options)
OutputVar

The name of variable in which to store the result reported by 7-zip.

Archive

Archive file name or path that will be tested.

Files (optional)

One or multiple files, path or file pattern that will be tested .
When multiple files are passed, they need to be separated by new line, e.g. "C:\File1.txt`nC:\File`nC:\MyDir"

Options (optional)

See supported switches in 7-zip Add() help.

Frequently Asked Questions (FAQ)

Can I use 7-Zip in a commercial organization?

Yes, 7-Zip is free software. You can use it on any computer. You don't need to register or pay for 7-Zip.

Why 7z archives created by new version of 7-Zip can be larger than archives created by old version of 7-Zip?

New versions of 7-Zip (starting from version 15.06) use another file sorting order by default for solid 7z archives.

Old version of 7-Zip (before version 15.06) used file sorting "by type" ("by extension").

New version of 7-Zip supports two sorting orders:

You can get big difference in compression ratio for different sorting methods, if dictionary size is smaller than total size of files. If there are similar files in different folders, the sorting "by type" can provide better compression ratio in some cases.

Note that sorting "by type" has some drawbacks. For example, NTFS volumes use sorting order "by name", so if an archive uses another sorting, then the speed of some operations for files with unusual order can fall on HDD devices (HDDs have low speed for "seek" operations).

You can increase compression ratio with the following methods:

If you think that unusual file order is not problem for you, and if better compression ratio with small dictionary is more important for you, use 'qs' mode.

Why can't 7-Zip open some ZIP archives?

In 99% of these cases it means that the archive contains incorrect headers. Other ZIP programs can open some archives with incorrect headers, since these programs just ignore errors.

If you have such archive, please don't call the 7-Zip developers about it. Instead try to find the program that was used to create the archive and inform the developers of that program that their software is not ZIP-compatible.

There are also some ZIP archives that were encoded with methods unsupported by 7-Zip, for example, WAVPack (WinZip).

Why doesn't the command line version add files without extensions to an archive?

You're probably using a *.* wildcard. 7-Zip doesn't use the operating system's wildcard mask parser, and consequently treats *.* as any file that has an extension. To process all files you must use the * wildcard instead or omit the wildcard altogether.

Why doesn't -r switch work as expected?

In most cases you don't need -r switch. 7-Zip can compress subfolders even without -r switch.

Example 1:

  a c:\a.7z "C:\Program Files"

compresses "C:\Program Files" completely, including all subfolders.

Example 2:

  a -r c:\a.7z "C:\Program Files"

searches and compresses "Program Files" in all subfolders of C:\ (for example, in "C:\WINDOWS").

If you need to compress only files with some extension, you can use -r switch:
  a -r c:\a.zip c:\dir\*.txt 

compresses all *.txt files from folder c:\dir\ and all it's subfolders.

How can I store full path of file in archive?

7-Zip stores only relative paths of files (without drive letter prefix). You can change current folder to folder that is common for all files that you want to compress and then you can use relative paths:

  cd /D C:\dir1\
  a c:\a.7z file1.txt dir2\file2.txt

Why can't 7-Zip use big dictionary in 32-bit Windows?

32-bit Windows allocates only 2 GB of virtual space per one application. Also that block of 2 GB can be fragmented (for example, by some DLL file), so 7-Zip can't allocate one big contiguous block of virtual space. There are no such limitations in 64-bit Windows. So you can use any dictionary in Windows x64, if you have required amount of physical RAM.

How can I recover corrupted 7z archive?

There are some possible cases when archive is corrupted:

It's possible to recover some data. Read about recovering procedure:

Recover corrupted 7z archive




Copyright (C) 2021 Igor Pavlov. The site is hosted at Digital Ocean