Page 1 of 1

[SOLVED] Path separators #PS, #NPS, #PS$, #NPS$

Posted: Tue Nov 08, 2022 1:52 pm
by Oso
Hello all, can someone confirm if #PS and #PS$ change their result according to the system type?

I noticed that the manual indicates #PS$ is a ' \'. I thought that #PS$ varied depending on the O/S and would be '/' on Unix systems...

"Specific OS path separator characters are available #PS, #NPS, #PS$ (’\’) and #NPS$ (’/’)"

On Windows I see these results...

Code: Select all

OpenConsole()
PrintN(Str(#PS))       ; 92
PrintN(Str(#NPS))      ; 47
PrintN(#PS$)           ; \
PrintN(#NPS$)          ; /
Input()
Below from 22nd January 2019...
"Added: #PS, #NPS, #PS$ and #NPS$ constants (Path seperator character depending of the OS)"
https://www.purebasic.com/news.php

Re: Path separators #PS, #NPS, #PS$, #NPS$

Posted: Tue Nov 08, 2022 2:30 pm
by Olli
Hello !

What I understood is that a path (or full path file name) can be written like this...

Code: Select all

root/directory/subdirectory/file.ext
... whatever the OS.

Hope you will have a more accurate answer.

Re: Path separators #PS, #NPS, #PS$, #NPS$

Posted: Tue Nov 08, 2022 3:00 pm
by NicTheQuick
Here's the output on Linux:

Code: Select all

Debug #PS       ; 47
Debug #NPS      ; 92
Debug #PS$      ; /
Debug #NPS$     ; \

Re: Path separators #PS, #NPS, #PS$, #NPS$

Posted: Tue Nov 08, 2022 3:38 pm
by collectordave
I have found that #PS$ returns "\" on windows and "/" on the Mac which seems to be correct.

Can anyone explain the use of #NPS$ it is the N which is getting me.

Re: Path separators #PS, #NPS, #PS$, #NPS$

Posted: Tue Nov 08, 2022 3:50 pm
by Oso
NicTheQuick wrote: Tue Nov 08, 2022 3:00 pm Here's the output on Linux:

Code: Select all

Debug #PS       ; 47
Debug #NPS      ; 92
Debug #PS$      ; /
Debug #NPS$     ; \
Thanks for trying this, NicTheQuick. That confirms what I originally thought, which is that #PS$ can be used on both Windows and Linux, without needing anything further. I remembered a post from BarryG a few weeks ago but couldn't find it. When I looked in the manual today, it's a bit confusing.

Re: Path separators #PS, #NPS, #PS$, #NPS$

Posted: Tue Nov 08, 2022 3:54 pm
by Oso
Olli wrote: Tue Nov 08, 2022 2:30 pm What I understood is that a path (or full path file name) can be written like this...

Code: Select all

root/directory/subdirectory/file.ext
... whatever the OS.
More or less, yes, but you would code it as...

Code: Select all

path.s = "root" + #PS$ + "directory" + #PS$ + "subdirectory" + #PS$ + "file.ext"

Re: Path separators #PS, #NPS, #PS$, #NPS$

Posted: Tue Nov 08, 2022 3:58 pm
by Oso
collectordave wrote: Tue Nov 08, 2022 3:38 pm I have found that #PS$ returns "\" on windows and "/" on the Mac which seems to be correct.
Can anyone explain the use of #NPS$ it is the N which is getting me.
Thanks. Yes, I was thinking exactly the same thing. The only reason I could possibly come up with, is if you're writing some code on Windows that generates some kind of output for Linux/Mac. For instance, building an ftp script to a Linux client. Yeah, it still seems weird though. :D

Re: Path separators #PS, #NPS, #PS$, #NPS$

Posted: Tue Nov 08, 2022 5:27 pm
by Demivec
From what I understand, #NPS$ is the 'Not' Path Separator string. In other words, the one for other OS's.

Re: Path separators #PS, #NPS, #PS$, #NPS$

Posted: Tue Nov 08, 2022 10:57 pm
by Oso
Demivec wrote: Tue Nov 08, 2022 5:27 pm From what I understand, #NPS$ is the 'Not' Path Separator string. In other words, the one for other OS's.
Yes, a good way to describe it. After you put it that way, I realised it could be very useful for validating a user's input of a pathname, i.e. to stop the user from entering that character because it isn't going to work on the system.

It's easier than checking for the use of the valid character.