[英]Why the Path.Combine is not combining the path and file?
I have this code: 我有以下代码:
string log_file_name = @"\logger.txt";
string logger_file_to_read = Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\log";
string LoggerFile = Path.Combine(logger_file_to_read, log_file_name);
I used a breakpoint and i see that : logger_file_to_read contain: 我使用了一个断点,发现:logger_file_to_read包含:
C:\\Users\\bout0_000\\AppData\\Local\\Diagnostic_Tool_Blue_Screen\\Diagnostic Tool Blue Screen\\log C:\\ Users \\ bout0_000 \\ AppData \\ Local \\ Diagnostic_Tool_Blue_Screen \\ Diagnostic Tool蓝屏\\ log
And that log_file_name contain: 该log_file_name包含:
\\logger.txt \\ logger.txt
But then i see that LoggerFile contain only the file name: \\logger.txt Without the directory. 但是然后我看到LoggerFile仅包含文件名:\\ logger.txt没有目录。
Whay is that ? 是哪个?
It's right there in the documentation : 就在文档中 :
If path2 does not include a root (for example, if path2 does not start with a separator character or a drive specification), the result is a concatenation of the two paths, with an intervening separator character.
如果path2不包含根(例如,如果path2不以分隔符或驱动器规范开头),则结果是两个路径的连接,中间插入了分隔符。 If path2 includes a root, path2 is returned.
如果path2包含根,则返回path2。
将反斜杠放在文件名中,如下所示:
string log_file_name = "logger.txt";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.