PDA

View Full Version : |Script| Dicas Delphi - Manipulando Arquivos e Pastas



DJ Thanatus
03-11-2023, 12:18 AM
Criar Pasta
Caso não existir, criará uma nova pasta


procedure CheckDirectoryInfo(path: String);
begin
if not DirectoryExists(path) then begin
ForceDirectories(path);
end;
end;


Exemplo de uso:


CheckDirectoryInfo('C:\Teste');




Verificar se determinado arquivo existe


function CheckFileInfo(path: String): Boolean;
begin
if FileExists(path) then begin
Result:=True;
end
else begin
Result:=False;
end;
end;


Exemplo de Uso:


if CheckFileInfo('C:\Teste\Arquivo.txt') = True then begin
ShowMessage('Arquivo encontrado');
end
else begin
ShowMessage('Arquivo não encontrado');
end;




Copiar Arquivo

Estrutura:
CopyFile(Arquivo de Origem, Destino, FailExist);

Exemplo de uso:


CopyFile(PChar('C:\Teste\Arquivo.txt'), PChar('C:\Jogo\Arquivo.txt'), False);



Deletar Arquivo

Estrutura:
DeleteFile(Nome do Arquivo);

Exemplo de uso:


DeleteFile('C:\Teste\Arquivo.txt');




Deletar Pasta

Estutura:
RemoveDir(Nome da Pasta);

Exemplo de uso:


RemoveDir('C:\Teste');




Renomear Arquivo

Estrutura:
RenameFile(Nome Atual, Novo Nome);

Exemplo de uso:


RenameFile('C:\Teste\Arquivo.txt', 'C:\Teste\NovoNome.txt');