Backslash convention for path and file names

  • Thread starter Thread starter John Dann
  • Start date Start date
J

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
 
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
 
John Dann said:
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'.
 
Back
Top