Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.StdCtrls, System.Zip;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- var
- ZipFile: TZipFile;
- SearchRec: TSearchRec;
- ArquivoOriginal: string;
- begin
- // Define o caminho da pasta de downloads
- ArquivoOriginal := 'C:\Users\' + GetEnvironmentVariable('USERNAME') + '\Downloads\';
- // Cria uma instância da classe TZipFile
- ZipFile := TZipFile.Create;
- try
- // Indica o diretório e nome do arquivo Zip que será criado
- ZipFile.Open(ArquivoOriginal + 'ArquivosCompactados.zip', zmWrite);
- // Procura por arquivos .zip na pasta de downloads
- if FindFirst(ArquivoOriginal + '*.zip', faAnyFile, SearchRec) = 0 then
- begin
- repeat
- // Adiciona o arquivo ao zip
- ZipFile.Add(ArquivoOriginal + SearchRec.Name);
- until FindNext(SearchRec) <> 0;
- // Libera os recursos usados pela função FindFirst
- FindClose(SearchRec);
- end;
- // Fecha o arquivo zip
- ZipFile.Close;
- finally
- // Libera o objeto da memória
- ZipFile.Free;
- end;
- end;
- end.
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement