www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Best way to add slash to tail of the path

reply "Suliman" <evermind live.ru> writes:
Sometimes it's path string may do not have tail slash of the path
Compare:

string path = "C:\\folder\\name"
string path = "C:\\folder\\name\\"

in case if I need to append file name to path to get full path I 
can get error like:
path ~= foo.txt
"C:\\folder\\namefoo.txt"
instead of
"C:\\folder\\name\\foo.txt"

what is the best way to add tail slash if it's not exists?
Nov 27 2014
parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Thu, 27 Nov 2014 18:05:37 +0000
Suliman via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
wrote:

 Sometimes it's path string may do not have tail slash of the path
 Compare:
=20
 string path =3D "C:\\folder\\name"
 string path =3D "C:\\folder\\name\\"
=20
 in case if I need to append file name to path to get full path I=20
 can get error like:
 path ~=3D foo.txt
 "C:\\folder\\namefoo.txt"
 instead of
 "C:\\folder\\name\\foo.txt"
=20
 what is the best way to add tail slash if it's not exists?
=20
see std.path, it contains alot of useful things.
Nov 27 2014
parent reply "Suliman" <evermind live.ru> writes:
 see std.path, it contains alot of useful things.
I looked there, but found only buildNormalizedPath, but it's not for such situation...
Nov 27 2014
parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Thu, 27 Nov 2014 20:02:40 +0000
Suliman via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
wrote:

 see std.path, it contains alot of useful things.
I looked there, but found only buildNormalizedPath, but it's not=20 for such situation...
take a second look then. ;-) you'll find `buildPath()` here too.
Nov 27 2014
parent reply "Suliman" <evermind live.ru> writes:
take a second look then. ;-) you'll find `buildPath()` here too.
Not better: string foo = "D:/code/txtDownloader"; writeln(foo); foo = foo.buildPath; foo ~= "config.txt"; writeln(foo); Running .\txtdownloader.exe D:/code/txtDownloader D:/code/txtDownloaderconfig.txt <-- need: D:/code/txtDownloader/config.txt
Nov 27 2014
next sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Thu, 27 Nov 2014 20:20:24 +0000
Suliman via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
wrote:

take a second look then. ;-) you'll find `buildPath()` here too.
Not better: =20 string foo =3D "D:/code/txtDownloader"; =20 writeln(foo); foo =3D foo.buildPath; foo ~=3D "config.txt"; writeln(foo); =20 =20 Running .\txtdownloader.exe D:/code/txtDownloader D:/code/txtDownloaderconfig.txt <-- need:=20 D:/code/txtDownloader/config.txt
and now try to read the documentation. it rocks. no, really, it was written for people to read it!
Nov 27 2014
parent reply "Suliman" <evermind live.ru> writes:
Could you quote for me part of docs where it's written? I really 
can't understand about what you are taking.
Nov 27 2014
next sibling parent Daniel Kozak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
try first few sentences and looked at the example ;)

Dne Thu, 27 Nov 2014 21:42:31 +0100 Suliman via Digitalmars-d-learn  
<digitalmars-d-learn puremagic.com> napsal(a):

 Could you quote for me part of docs where it's written? I really can't  
 understand about what you are taking.
-- Vytvořeno poštovní aplikací Opery: http://www.opera.com/mail/
Nov 27 2014
prev sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Thu, 27 Nov 2014 20:42:31 +0000
Suliman via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
wrote:

 Could you quote for me part of docs where it's written? I really=20
 can't understand about what you are taking.
right here: http://dlang.org/phobos/std_path.html#buildPath do you see examples section there? you don't even have to read the explanations, as examples are self-explanatory. please, try to read *the* *whole* *docs* on the given function next time. it's very boring to answer the questions that are already answered in documentation, and even demonstrated with samples. almost all your questions here are easily answered by careful reading of documentation.
Nov 27 2014
next sibling parent "Suliman" <evermind live.ru> writes:
thanks! I understood!
Nov 27 2014
prev sibling parent "Evil Satanson" <ihatewindoz gmail.com> writes:
On Thursday, 27 November 2014 at 20:52:26 UTC, ketmar via 
Digitalmars-d-learn wrote:
 On Thu, 27 Nov 2014 20:42:31 +0000
 Suliman via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com>
 wrote:

 Could you quote for me part of docs where it's written? I 
 really can't understand about what you are taking.
right here: http://dlang.org/phobos/std_path.html#buildPath do you see examples section there? you don't even have to read the explanations, as examples are self-explanatory. please, try to read *the* *whole* *docs* on the given function next time. it's very boring to answer the questions that are already answered in documentation, and even demonstrated with samples. almost all your questions here are easily answered by careful reading of documentation.
Don't bother, he is useless.. I've known him for a quite few years :-D Just ignore the stupid questions, this way people would be forced to really look for answers. RTFM 4eva! :-D
Nov 27 2014
prev sibling parent Daniel Kozak via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
Dne Thu, 27 Nov 2014 21:20:24 +0100 Suliman via Digitalmars-d-learn  
<digitalmars-d-learn puremagic.com> napsal(a):

 take a second look then. ;-) you'll find `buildPath()` here too.
Not better: string foo = "D:/code/txtDownloader"; writeln(foo); foo = foo.buildPath; foo ~= "config.txt"; writeln(foo); Running .\txtdownloader.exe D:/code/txtDownloader D:/code/txtDownloaderconfig.txt <-- need: D:/code/txtDownloader/config.txt
what about: string foo = "D:/code/txtDownloader"; writeln(foo); foo = buildPath(foo, "config.txt"); writeln(foo);
Nov 27 2014