Olá galera, nesta Quick Tips, irei continuar a mostrar a nova Unit IOUtils do Delphi 2010, algumas funções mais utilizadas que temos nela.

 

Vamos agora ver o Record TPath, vamos criar uma variável Caminho do tipo String para podermos trabalhar com um único arquivo

 

ChangeExtension

Descrição: Podemos mudar a extensão de um arquivo, porém não muda fisicamente.

 

Exemplo:

procedure TFrmPrincipal.Button2Click(Sender: TObject);

Var

Path : TPath;

Arquivo : String;

begin

Arquivo := 'D:\Lista.txt';

ShowMessage(Path.ChangeExtension(Arquivo, 'rar'));

end;

 

GetDirectoryName

Descrição: Podemos verificar o nome do caminho completo.

 

Exemplo:

 

procedure TFrmPrincipal.Button3Click(Sender: TObject);

Var

Path : TPath;

Arquivo : String;

begin

Arquivo := 'D:\Lista.txt';

ShowMessage(Path.GetDirectoryName(Arquivo));

end;

 

GetExtension

Descrição: Podemos verificar a extensão do arquivo.

 

Exemplo:

procedure TFrmPrincipal.Button4Click(Sender: TObject);

Var

Path : TPath;

Arquivo : String;

begin

Arquivo := 'D:\Lista.txt';

ShowMessage(Path.GetExtension(Arquivo));

end;

 

GetFileName

Descrição: Podemos verificar o nome e extensão do arquivo.

 

Exemplo:

procedure TFrmPrincipal.Button5Click(Sender: TObject);

Var

Path : TPath;

Arquivo : String;

begin

Arquivo := 'D:\Lista.txt';

ShowMessage(Path.GetFileName(Arquivo));

end;

 

GetFileNameWithoutExtension

Descrição: Podemos verificar o nome do arquivo sem a extensão.

 

Exemplo:

procedure TFrmPrincipal.Button6Click(Sender: TObject);

Var

Path : TPath;

Arquivo : String;

begin

Arquivo := 'D:\Lista.txt';

ShowMessage(Path.GetFileNameWithoutExtension(Arquivo));

end;

 

GetFullPath

Descrição: Podemos verificar o caminho completo, assim como o nome do arquivo e sua extensão.

 

Exemplo:

procedure TFrmPrincipal.Button7Click(Sender: TObject);

Var

Path : TPath;

Arquivo : String;

begin

Arquivo := 'D:\Lista.txt';

ShowMessage(Path.GetFullPath(Arquivo));

end;

 

GetPathRoot

Descrição: Podemos verificar o diretório raiz do arquivo.

 

Exemplo:

procedure TFrmPrincipal.Button8Click(Sender: TObject);

Var

Path : TPath;

Arquivo : String;

begin

Arquivo := 'D:\Lista.txt';

ShowMessage(Path.GetPathRoot(Arquivo));

end;

 

GetTempPath

Descrição: Podemos verificar a pasta de arquivos temporários do Windows.

 

Exemplo:

procedure TFrmPrincipal.Button9Click(Sender: TObject);

Var

Path : TPath;

Arquivo : String;

begin

Arquivo := 'D:\Lista.txt';

ShowMessage(Path.GetTempPath);

end;

 

 

Fico por aqui ate à próxima Quick Tips.

 

Um abraço

 

Wesley Y

wyamazack@rwsolution.com.br