C# 为什么Path.Combine没有合并路径和文件?
我有以下代码:C# 为什么Path.Combine没有合并路径和文件?,c#,winforms,C#,Winforms,我有以下代码: 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); 我使用了一个断点,我看到
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);
我使用了一个断点,我看到:logger_file_to_read包含:
C:\Users\bout0\u 000\AppData\Local\Diagnostic\u Tool\u Blue\u Screen\Diagnostic Tool Blue Screen\log
该日志文件名包含:
\logger.txt
但是我看到LoggerFile只包含文件名:\logger.txt
没有目录
那是什么?就在那里的:
例如,如果path2不包括根,如果path2不以分隔符或驱动器规格开头,则结果是两条路径的串联,中间带有分隔符。如果路径2包含根,则返回路径2
就在那里的:
例如,如果path2不包括根,如果path2不以分隔符或驱动器规格开头,则结果是两条路径的串联,中间带有分隔符。如果路径2包含根,则返回路径2
在文件名中删除反斜杠,如下所示:
string log_file_name = "logger.txt";
在文件名中删除反斜杠,如下所示:
string log_file_name = "logger.txt";
因此OP应该设置log_file_name=logger.txt;没有``所以OP应该设置log\u file\u name=logger.txt;没有``