c# - What are the consequences, if any, of multiple backslashes in Windows paths? -
in programs have file names and/or paths configured in app.config file. like:
<add key="logfiledirectory" value="c:\logs" /> <add key="savelogfileto" value="mylogfile.txt" />
in actual application code, i'll concatenate these code similar this:
var logfile = configurationmanager.appsettings["logfiledirectory"] + @"\" + configurationmanager.appsettings["savelogfileto"];
now, result of above code give log file path of c:\logs\mylogfile.txt
, however, if end-user specifies log file directory in configuration file c:\logs\
trailing backslash, code results in actual path of c:\logs\\mylogfile.txt
double backslash between directory , file.
in experience, works fine in practice. matter of fact, dropping command prompt , executing cd c:\\\\\\windows\\\
works in practice.
my question is, what, if any, consequences of having paths this? don't want using "feature" in production code if undocumented , subject broken @ point in future new release of windows.
there no consequences know of, , it's not broken in future versions, because lot of people doing same you.
however, correct way combine paths in c# use path.combine
, remove backslashes you:
var logfile = path.combine( configurationmanager.appsettings["logfiledirectory"], configurationmanager.appsettings["savelogfileto"]);
Comments
Post a Comment