Advertisement
miguelhosttimer

zipa tudo na pasta Downloads

May 15th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.45 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.StdCtrls, System.Zip;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     procedure Button1Click(Sender: TObject);
  13.   private
  14.     { Private declarations }
  15.   public
  16.     { Public declarations }
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.dfm}
  25.  
  26. procedure TForm1.Button1Click(Sender: TObject);
  27.  
  28.  
  29.  var
  30.   ZipFile: TZipFile;
  31.   SearchRec: TSearchRec;
  32.   ArquivoOriginal: string;
  33. begin
  34.   // Define o caminho da pasta de downloads
  35.   ArquivoOriginal := 'C:\Users\' + GetEnvironmentVariable('USERNAME') + '\Downloads\';
  36.  
  37.   // Cria uma instância da classe TZipFile
  38.   ZipFile := TZipFile.Create;
  39.   try
  40.     // Indica o diretório e nome do arquivo Zip que será criado
  41.     ZipFile.Open(ArquivoOriginal + 'ArquivosCompactados.zip', zmWrite);
  42.  
  43.     // Procura por arquivos .zip na pasta de downloads
  44.     if FindFirst(ArquivoOriginal + '*.zip', faAnyFile, SearchRec) = 0 then
  45.     begin
  46.       repeat
  47.         // Adiciona o arquivo ao zip
  48.         ZipFile.Add(ArquivoOriginal + SearchRec.Name);
  49.       until FindNext(SearchRec) <> 0;
  50.  
  51.       // Libera os recursos usados pela função FindFirst
  52.       FindClose(SearchRec);
  53.     end;
  54.  
  55.     // Fecha o arquivo zip
  56.     ZipFile.Close;
  57.   finally
  58.     // Libera o objeto da memória
  59.     ZipFile.Free;
  60.   end;
  61. end;
  62.  
  63. end.
  64.  
  65.  
  66. end;
  67.  
  68. end.
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement