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

Just starting out? Need help? Post your questions and find answers here.
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

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

Post 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
Last edited by Oso on Mon Jan 30, 2023 7:43 pm, edited 1 time in total.
Olli
Addict
Addict
Posts: 1196
Joined: Wed May 27, 2020 12:26 pm

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

Post 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.
User avatar
NicTheQuick
Addict
Addict
Posts: 1503
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

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

Post by NicTheQuick »

Here's the output on Linux:

Code: Select all

Debug #PS       ; 47
Debug #NPS      ; 92
Debug #PS$      ; /
Debug #NPS$     ; \
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

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

Post 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.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

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

Post 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.
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

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

Post 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"
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

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

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4259
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

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

Post by Demivec »

From what I understand, #NPS$ is the 'Not' Path Separator string. In other words, the one for other OS's.
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

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

Post 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.
Post Reply