Recent

Author Topic: [RESOLVED] Get absolute path of file or directory  (Read 11560 times)

bubulemaster

  • New Member
  • *
  • Posts: 47
[RESOLVED] Get absolute path of file or directory
« on: January 12, 2010, 05:32:27 pm »
Hi,

do you know if in Lazarus or Freepascal, we can find a function to get absolute path of example '/truc/../something' -> '/something'.

I found nothing about it in this forum or on google

Thanks
« Last Edit: January 14, 2010, 08:57:47 am by bubulemaster »

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: Get absolute path of file or directory
« Reply #1 on: January 12, 2010, 08:02:57 pm »
In unit FileUtil, there are

function CreateAbsoluteSearchPath(const SearchPath, BaseDirectory: string): string;
function CreateRelativePath(const Filename, BaseDirectory: string): string;

Don't know it this is what you're looking for.

bubulemaster

  • New Member
  • *
  • Posts: 47
Re: Get absolute path of file or directory
« Reply #2 on: January 13, 2010, 10:38:03 am »
Not really.

Exemple, on windows :

  writeln(
      CreateAbsoluteSearchPath(
          '/truc/../machin',
          '/bidule/')) ;

Out : /bidule/\/truc/../machin

  writeln(
      CreateAbsoluteSearchPath(
          'c:\truc\..\machin',
          'c:\bidule\')) ;

Out : c:\truc\..\machin

I going create my own function

Thanks for your help

eny

  • Hero Member
  • *****
  • Posts: 1653
Re: Get absolute path of file or directory
« Reply #3 on: January 13, 2010, 11:49:43 am »
ExpandFileName?
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

mmab

  • Jr. Member
  • **
  • Posts: 89
Re: Get absolute path of file or directory
« Reply #4 on: January 13, 2010, 12:27:17 pm »
You can use parse function to extract what you want from the directory and

Code: [Select]
function Parse(Char, S: string; Count: Integer): string;
var
  I: Integer;
  T: string;
begin
  if S[Length(S)] <> Char then
    S := S + Char;
  for I := 1 to Count do
  begin
    T := Copy(S, 0, Pos(Char, S) - 1);
    S := Copy(S, Pos(Char, S) + 1, Length(S));
  end;
  Result := T;
end;   
CALL:
for ex.you want the first section of the dirname separated by  '\' under windows :
             {$IFDEF WINDOWS}
                F1 := Parse('\', dirname ,1)
             {$ENDIF}
you can use this function to get different parts of the dirname and do what you want

eny

  • Hero Member
  • *****
  • Posts: 1653
Re: Get absolute path of file or directory
« Reply #5 on: January 13, 2010, 01:14:54 pm »
StrUtils.ExtractWord?
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

bubulemaster

  • New Member
  • *
  • Posts: 47
Re: Get absolute path of file or directory
« Reply #6 on: January 14, 2010, 08:57:32 am »
ExpandFileName?

Yes ! This is what I need.

Thank you

 

TinyPortal © 2005-2018