我有这个代码:
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_000\AppData\Local\Diagnostic_Tool_Blue_Screen\诊断工具蓝屏\log
那个 log_file_name 包含:
\记录器.txt
但后来我看到 LoggerFile 只包含文件名:\logger.txt 没有目录。
那是什么?
最佳答案
它就在 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. If path2 includes a root, path2 is returned.
关于c# - 为什么 Path.Combine 没有合并路径和文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18008276/