Home All Groups Group Topic Archive Search About

Backslash convention for path and file names

Author
2 Jul 2006 9:14 AM
John Dann
I guess there must be some convention or Windows specification for
whether the backslash immediately preceding the file name in a full
path string to a file is formally part of the path string or of the
file name. I suppose the options are:

1. Part of the path string, ie all returned path strings should have a
trailing backslash.

2. Part of the file name, ie all file names should start with a
backslash.

3. Neither, in which case one should presumably always expect to add a
backslash explicitly to the file name when building the full path
string to a file from its constituent path and file name.

Anyone enlighten me please as to what the preferred practice might be?

JGD

Author
2 Jul 2006 9:50 AM
Mattias Sjögren
John,

>3. Neither, in which case one should presumably always expect to add a
>backslash explicitly to the file name when building the full path
>string to a file from its constituent path and file name.
>
>Anyone enlighten me please as to what the preferred practice might be?

Use the System.IO.Path class for building the path. That way, you
don't have to worry about it yourself.

Personally I see the backslash as a separator, and therefore it's not
really part of either side.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
2 Jul 2006 12:41 PM
Herfried K. Wagner [MVP]
"John Dann" <n***@prodata.co.uk> schrieb:
> 3. Neither, in which case one should presumably always expect to add a
> backslash explicitly to the file name when building the full path
> string to a file from its constituent path and file name.

Simply use 'System.IO.Path.Combine'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>