How to get last folder in directory path?
How to get last folder in directory path?
Hi all! How do you get the last directory folder from a directory path string?
Example :
I have a folder in C:/ called 'out'
C:/out/
I want to grab 'out' without the slashes
Any & all help is both welcome & appreciated!
Thank You! <3
Example :
I have a folder in C:/ called 'out'
C:/out/
I want to grab 'out' without the slashes
Any & all help is both welcome & appreciated!
Thank You! <3
Re: How to get last folder in directory path?
Code: Select all
Path$ = "C:/out/"
Debug GetFilePart(Trim(Path$, "/"))
i = CountString(Path$, "/")
Debug StringField(Path$, i, "/")
Re: How to get last folder in directory path?
What if the directory as a backslash at the end without another folder after it? For some reason, the above 2 codes are returning nothing.
D:\res\src\libs\out\
D:\res\src\libs\out\
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: How to get last folder in directory path?
Look at Peace's two code snippets: What kind of slashes do they use? Are they using backslashes?Mythros wrote:What if the directory as a backslash at the end without another folder after it? For some reason, the above 2 codes are returning nothing.
D:\res\src\libs\out\
Re: How to get last folder in directory path?
yes, backslashes
Re: How to get last folder in directory path?
Change "/" in "\" for a real path, your first question related to a path with a "/", I simply copied your "C:/out/"Mythros wrote:What if the directory as a backslash at the end without another folder after it? For some reason, the above 2 codes are returning nothing.
D:\res\src\libs\out\
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: How to get last folder in directory path?
False.Mythros wrote:yes, backslashes
Peace's code snippets use forward slashes. So it shouldn't be surprising that they don't work with backslashes.
Re: How to get last folder in directory path?
<OT>
To be sure to use the correct path separator independent of the OS, you can use the constant #PS$.
</OT>
To be sure to use the correct path separator independent of the OS, you can use the constant #PS$.
Code: Select all
Debug #PS$
Debug #NPS$
</OT>
Hygge
Re: How to get last folder in directory path?
Thanks guys!
Re: How to get last folder in directory path?
now I'm going to hear guns and roses every time I use a "/"Kiffi wrote:<OT>
To be sure to use the correct path separator independent of the OS, you can use the constant #PS$.
Code: Select all
Debug #PS$ Debug #NPS$
</OT>
Windows 11, Manjaro, Raspberry Pi OS