Como remover ultimo nome em um caminho de diretório???

Delphi

31/10/2004

Tenho que remover o último nome de uma string, para facilitar vou dar um exemplo:


vCaminho := c:\delphi\teste\tudook

gostaria de que a variável vCaminho ficasse com o valor:

vCaminho := c:\delphi\teste


Emir Neto

Emir Neto

Curtidas 0

Respostas

Reginaldo174

Reginaldo174

31/10/2004

Vcaminho := ExtractFilePath(c:\delphi\teste\tudook.exe);


GOSTEI 0
Emir Neto

Emir Neto

31/10/2004

Perceba que tudook é uma pasta e não um arquivo, por isso que está errado. Será que tens a resposta?


GOSTEI 0
Tatuweb

Tatuweb

31/10/2004

Tente assim:

function GetPathFolder (Path: string): string;
var
  LenPath, i, j: Word;
begin
  LenPath := Length (Path);

  if Pos (´\´, Path) = 0 then
  begin
    Result := ´Erro: Caminho Inválido!´;
    Exit;
  end;

  if LenPath = 3 then
  begin
    Result := Path;
    Exit;
  end;

  if Copy (Path, LenPath, 1) = ´\´ then
    Path := Copy (Path, 1, LenPath - 1);

  for i := 0 to LenPath do
    if Path[i] = ´\´ then j := i;
  Result := Copy (Path, 1, j);
end;

e para chamar:

  ShowMessage (GetPathFolder (´c:\delphi\teste\tudook´));



GOSTEI 0
Emir Neto

Emir Neto

31/10/2004

era isso mesmo. Obrigado.


GOSTEI 0
POSTAR