Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-08

ExtractRelativePath() not always returning expected result

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

James Richters

I’m trying to figure out ExtractRelativePath() and I’ve run the sample program found here:

https://www.freepascal.org/docs-html/rtl/sysutils/extractrelativepath.html

I get the following results from the sample (with a few test I threw in myself):

Show quoted text 13 lines
From "/pp/src/compiler" to "/pp/bin/win32/ppc386" via "..\bin\win32\ppc386" // Shouldn’t this be “..\..\bin\win32\ppc386” ? From "/pp/bin/win32/ppc386" to "/pp/src/compiler" via "..\..\src\compiler" // Shouldn’t this be "..\..\..\src\compiler" ? From "e:/pp/bin/win32/ppc386" to "d:/pp/src/compiler" via "d:/pp/src/compiler" //Expected From "e:\pp\bin\win32\ppc386" to "d:\pp\src\compiler" via "d:\pp\src\compiler" //Expected From "C:\FPC\3.0.2" to "C:\FPC\3.0.2" via "3.0.2" // Shouldn’t this be “” since we are already there? From "C:\FPC\3.0.2" to "C:\FPC\3.0.4rc1" via "3.0.4rc1" // Shouldn’t this be "..\3.0.4rc1"? From "Q:\" to "Q:\FPC\3.0.4rc1" via "FPC\3.0.4rc1" //Expected

Am I missing something here?

James

Michael Van Canneyt
to James Richters
James Richters wrote 9 lines
I’m trying to figure out ExtractRelativePath() and I’ve run the sample program found here: https://www.freepascal.org/docs-html/rtl/sysutils/extractrelativepath.html I get the following results from the sample (with a few test I threw in myself): > From "/pp/src/compiler" to "/pp/bin/win32/ppc386" via "..\bin\win32\ppc386" // Shouldn’t this be “..\..\bin\win32\ppc386” ?

You must make sure directories are appended with /

Michael.

James Richters
to Michael Van Canneyt
You must make sure directories are appended with /

Thank you, I just tried that and now I get the expected results: both / and \ work

Show quoted text 7 lines
From "/pp/src/compiler/" to "/pp/bin/win32/ppc386/" via "..\..\bin\win32\ppc386\" From "/pp/bin/win32/ppc386/" to "/pp/src/compiler/" via "..\..\..\src\compiler\" From "e:/pp/bin/win32/ppc386/" to "d:/pp/src/compiler/" via "d:/pp/src/compiler/" From "e:\pp\bin\win32\ppc386/" to "d:\pp\src\compiler/" via "d:\pp\src\compiler/" From "C:\FPC\3.0.2\" to "C:\FPC\3.0.2\" via "" From "C:\FPC\3.0.2\" to "C:\FPC\3.0.4rc1\" via "..\3.0.4rc1\" From "Q:\" to "Q:\FPC\3.0.4rc1\" via "FPC\3.0.4rc1\"

I guess the example program should have the trailing / in the examples to make it clear they are needed. None of the sample test cases have trailing / or \

I am curious about this though:

From "/pp/src/compiler/" to "/pp/bin/win32/ppc386/" via "..\..\bin\win32\ppc386\"

Shouldn't the output use / since / was used in both the source and destination not \ ?

James

Michael Van Canneyt
to James Richters
James Richters wrote 13 lines
> You must make sure directories are appended with / Thank you, I just tried that and now I get the expected results: both / and \ work From "/pp/src/compiler/" to "/pp/bin/win32/ppc386/" via "..\..\bin\win32\ppc386\" From "/pp/bin/win32/ppc386/" to "/pp/src/compiler/" via "..\..\..\src\compiler\" From "e:/pp/bin/win32/ppc386/" to "d:/pp/src/compiler/" via "d:/pp/src/compiler/" From "e:\pp\bin\win32\ppc386/" to "d:\pp\src\compiler/" via "d:\pp\src\compiler/" From "C:\FPC\3.0.2\" to "C:\FPC\3.0.2\" via "" From "C:\FPC\3.0.2\" to "C:\FPC\3.0.4rc1\" via "..\3.0.4rc1\" From "Q:\" to "Q:\FPC\3.0.4rc1\" via "FPC\3.0.4rc1\" I guess the example program should have the trailing / in the examples to make it clear they are needed. None of the sample test cases have trailing / or \

Can you please file a bugreport for that, so I will not forget it ?

I am curious about this though: From "/pp/src/compiler/" to "/pp/bin/win32/ppc386/" via "..\..\bin\win32\ppc386\" Shouldn't the output use / since / was used in both the source and destination not \ ?

The default for the OS is used; This is by design.

Michael.

James Richters
to Michael Van Canneyt
Can you please file a bugreport for that, so I will not forget it ?

Done.

The default for the OS is used; This is by design.

That makes sense for most cases but is there / could there be a way to override this? I normally write programs for Windows, however I've had to write out the Linux Slashes on my windows system before. An example is writing out a playlist files, and if I use the linux / the file would be useable on both windows and linux, but if I use the windows \ it only worked on windows.