c# - 为什么 Path.Combine 没有合并路径和文件?

标签 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);

我使用了一个断点,我看到: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/

相关文章:

c# - SSRS 报告中令人讨厌的 NULL 复选框

winforms - 在 Winform 中将 UserControl 从工作线程添加到主 UI 线程时发生跨线程冲突

c# - 无法并行运行测试(Selenium grid + NUnit)

c# - XpsDocument GetFixedDocumentSequence 为特定计算机生成的文件返回 null

c# - Winform - 确定鼠标是否离开用户控制

c# - 运行后如何隐藏WinForm?

c# - 通过 C# 中的方法强制添加到集合的模式

c# - 无法读取 ReturnUrl 查询字符串

c# - 在 SSIS 中将月份名称转换为月份编号

.net - 当索引未更改时触发列表框事件 SelectedIndexChanged