Arquivos - retornando nome curto e longo |
Top Previous Next |
|
procedure TForm1.Button1Click(Sender: TObject); var ShortPath: string; begin SetLength (ShortPath, 50); GetShortPathName (PChar ('e:\arquivos de programas\borland\delphi 3'),PChar (ShortPath), 50); ShowMessage (ShortPath); end;
-------------------------- OUTRAS FUNCOES --------------------------------
function NomeLongoparaCurto(const NomeLongo: string): string; begin // Acerta tamanho para o nome curto SetLength(Result,MAX_PATH); if GetShortPathName(PChar(NomeLongo), PChar(Result), Length(Result)) = 0 then Result := '' else SetLength(Result,StrLen(PChar(Result))); end;
function LongoParaCurto(const NomeLongo: string): string; var Win32FindData : TWin32FindData; Handle : THandle; i : Integer; begin // separa drive Result := ExtractFileDrive(NomeLongo); // vai pegando os nomes curtos do diretório for i := 0 to Length(NomeLongo) do if NomeLongo[i] = '\' then begin Handle := FindFirstFile(PChar(Copy(NomeLongo,1,i-1)), Win32FindData); if Handle <> INVALID_HANDLE_VALUE then begin // junta o nome obtido anteriormente Result := Result+'\'+String(Win32FindData.cAlternateFileName); Windows.FindClose(Handle); end; end; // pega o nome curto final if Copy(NomeLongo,Length(const NomeLongo),1) <> '\' then begin Handle := FindFirstFile(PChar(NomeLongo), Win32FindData); if Handle <> INVALID_HANDLE_VALUE then begin Result := Result+'\'+String(Win32FindData.cAlternateFileName); Windows.FindClose(Handle); end; end; end;
function NomeCurtoParaLongo(NomeCurto: string): string; var Win32FindData : TWin32FindData; Handle : THandle; i : Integer; begin // separa drive Result := ExtractFileDrive(NomeCurto); // vai pegando os nomes longos do diretório for i := 0 to Length(NomeCurto) do if NomeCurto[i] = '\' then begin Handle := FindFirstFile(PChar(Copy(NomeCurto,1,i-1)), Win32FindData); if Handle <> INVALID_HANDLE_VALUE then begin // junta o nome obtido anteriormente Result := Result + '\' + string(Win32FindData.cFileName); Windows.FindClose(Handle); end; end; // pega o nome longo final if Copy(NomeCurto,Length(NomeCurto),1) <> '\' then begin Handle := FindFirstFile(PChar(NomeCurto), Win32FindData); if Handle <> INVALID_HANDLE_VALUE then begin Result := Result + '\' + string(Win32FindData.cFileName); Windows.FindClose(Handle); end; end; end;
|