Function Reference


_WinAPI_SetCompression

Sets the compression state of a file or directory

#include <WinAPIFiles.au3>
_WinAPI_SetCompression ( $sFilePath, $iCompression )

Parameters

$sFilePath The path to the file or directory to be compressed.
$iCompression The compression state. This parameter can be one of the following values.
$COMPRESSION_FORMAT_NONE
$COMPRESSION_FORMAT_DEFAULT
$COMPRESSION_FORMAT_LZNT1

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.

Remarks

If the file system of the volume containing the specified file or directory does not support per-file or
per-directory compression, the function fails. File compression is supported for files of a maximum uncompressed
size of 30 gigabytes.

See Also

Search FSCTL_SET_COMPRESSION in MSDN Library.

Example

#include <APISysConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Local $sFile = FileOpenDialog('Select File', @ScriptDir, 'All Files (*.*)', BitOR($FD_FILEMUSTEXIST, $FD_PATHMUSTEXIST))
If @error Then Exit

Switch _WinAPI_GetCompression($sFile)
        Case -1
                MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Compression File', 'Unable to perform operation.')
        Case $COMPRESSION_FORMAT_NONE
                If _WinAPI_SetCompression($sFile, $COMPRESSION_FORMAT_DEFAULT) Then
                        MsgBox(($MB_ICONINFORMATION + $MB_SYSTEMMODAL), 'Compression File', 'The file compressed is successfully.')
                Else
                        MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Compression File', 'Unable to compress file.')
                EndIf
        Case Else
                If MsgBox(($MB_YESNO + $MB_ICONQUESTION + $MB_SYSTEMMODAL), 'Compression File', 'The file is already compressed.' & @CRLF & @CRLF & 'Decompress?') = 6 Then
                        If _WinAPI_SetCompression($sFile, $COMPRESSION_FORMAT_NONE) Then
                                MsgBox(($MB_ICONINFORMATION + $MB_SYSTEMMODAL), 'Compression File', 'The file decompressed is successfully.')
                        Else
                                MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Compression File', 'Unable to decompress file.')
                        EndIf
                EndIf
EndSwitch