Var tmpError, tmpParentPath, tmpSub, tmpOutput: String; tmpOptions: TStringList; Const ctZipPassword = ''; ctZipExt = '.zip'; // other compression formats are possible like '.7z' ctOutputPath = 'C:\Test\Out_Zip\'; // Must end with a \ // This function strips the last subfolder so it contains its parent folder Function GetParentPath(Const aPathName: string): String; var j: integer; tmpPathLen: integer; tmpPathName: String; Begin tmpPathName := aPathName; tmpPathLen := Length(tmpPathName); for j := (tmpPathLen - 1) downto 1 do If tmpPathName[j] = '\' Then Break; SetLength(tmpPathName, j); Result := tmpPathName; End; Begin // Init Var psExitCode:= 0; // When 0 then this means error occured. tmpParentPath := GetParentPath(psFilePath); tmpSub := psStringReplace(psFilePath, tmpParentPath, ''); tmpSub := psGetValidFilename(tmpSub); tmpOutput := ctOutputPath + tmpSub + ctZipExt; // ... add your code here tmpOptions := TStringList.Create; Try psLogWrite(1, '', 'Zip Subfolder ' + psFilePath); // Set Options // ScanSubDirectories = False, True (default: True) tmpOptions.Add('ScanSubDirectories' + tmpOptions.NameValueSeparator + 'True'); // FileIncludeFilter = (default: *.*) tmpOptions.Add('FileIncludeFilter' + tmpOptions.NameValueSeparator + '*.*'); // DuplicateCheck = None, Existing, All (default: Existing) tmpOptions.Add('DuplicateCheck' + tmpOptions.NameValueSeparator + 'Existing'); // DuplicateAction = Overwrite, Error, Skip (default: Overwrite) tmpOptions.Add('DuplicateAction' + tmpOptions.NameValueSeparator + 'Overwrite'); // AddDirectory = False, True (default: True) tmpOptions.Add('AddDirectory' + tmpOptions.NameValueSeparator + 'True'); // CompressionMethod = Copy, Deflate, Deflate64, BZip2, LZMA, LZMA2, PPMd (default: Deflate) tmpOptions.Add('CompressionMethod' + tmpOptions.NameValueSeparator + 'Deflate'); // EncryptionMethod = None, AES128, AES192, AES256, ZipCrypto (default: ZipCrypto) tmpOptions.Add('EncryptionMethod' + tmpOptions.NameValueSeparator + 'ZipCrypto'); // Level = 0..9 (default: 7) tmpOptions.Add('Level' + tmpOptions.NameValueSeparator + '7'); // Threads = 1 .. 255 (default: 1) tmpOptions.Add('Threads' + tmpOptions.NameValueSeparator + '1'); // Compress If ps7zCompress(psFilePath, tmpOutput, ctZipPassword, tmpOptions) Then Begin psLogWrite(1, '', 'Zipped Subfolder ' + psfilePath + ' to ' + tmpOutput + ' successful'); psExitCode := 1; End Else Begin // Options return in case of error: Error = 'Error Description' tmpError := tmpOptions.Values['Error']; psLogWrite(1, '', 'Zip Subfolder ' + psFilePath + ' to ' + tmpOutput +' error: ' + tmpError); End; Finally tmpOptions.Free; End; End.