Recent

Author Topic: Strange result of SysUtils.ExtractRelativePath  (Read 1486 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2402
    • UVviewsoft
Strange result of SysUtils.ExtractRelativePath
« on: January 28, 2022, 06:33:54 pm »
Code: Pascal  [Select][+][-]
  1. uses sysutils;
  2. begin
  3.   Writeln(ExtractRelativePath('/home/a/b/file.json', 'name.json'));
  4. end.
  5.  

Prints
Quote
../../../name.json

I am not sure it's ok result.
Maybe FPC pre-3.2 gave another result, cannot check now.

user@PC:~/fpcupdeluxe/fpcupdeluxe32/fpc/bin/x86_64-linux$ ./fpc
Free Pascal Compiler version 3.2.3-556-gc0f20e0e5f-dirty [2021/11/28] for x86_64

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Strange result of SysUtils.ExtractRelativePath
« Reply #1 on: January 28, 2022, 06:53:16 pm »
Maybe FPC pre-3.2 gave another result, cannot check now.
Same result for 3.0.4 and trunk.
So, if it is a bug, at least it's consistent.

Bart
« Last Edit: January 28, 2022, 10:08:39 pm by Bart »

WooBean

  • Full Member
  • ***
  • Posts: 230
Re: Strange result of SysUtils.ExtractRelativePath
« Reply #2 on: January 28, 2022, 07:04:11 pm »
Hi,
from LHelp we have:

"function ExtractRelativePath(const BaseName: UnicodeString;  const DestName: UnicodeString):UnicodeString;
...
Note that directories must end on a path delimiter for this function to work correctly. If not, the last part is stripped and treated as a file name. "

So, there is no bug.
Platforms: Win7/64, Linux Mint Ulyssa/64

Kays

  • Hero Member
  • *****
  • Posts: 575
  • Whasup!?
    • KaiBurghardt.de
Re: Strange result of SysUtils.ExtractRelativePath
« Reply #3 on: January 30, 2022, 02:51:03 pm »
ExtractRelativePath expects two absolute paths (or at least two starting from the same directory). If name.json was in the same directory as file.json, the “relative” path name.json is already the relative path you intend to extract, so you using this routine is pointless.
Yours Sincerely
Kai Burghardt

 

TinyPortal © 2005-2018