转自:https://www.cnblogs.com/51net/p/12172436.html

Windows和Linux路径分隔符不一样

C#开发语言中的路径分隔符为:Path.DirectorySeparatorChar

测试:

public ActionResult<object> PathTest()
{
    var baseDirectory = AppContext.BaseDirectory;

    var customDirectory = Path.Combine(baseDirectory, "xxx\\trace.log");

    var customDirectory2 = Path.Combine(baseDirectory, "\\xxx\\trace.log");

    var customDirectoryReplaced = customDirectory.Replace('\\', Path.DirectorySeparatorChar);

    return new
    {
        baseDirectory,
        customDirectory,
        customDirectory2,
        customDirectoryReplaced,
        Path.AltDirectorySeparatorChar,
        Path.DirectorySeparatorChar,
        Path.PathSeparator,
        Path.VolumeSeparatorChar
    };
}

相关文章:

  • 2021-11-14
  • 2021-07-19
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-15
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
  • 2021-09-13
  • 2021-12-13
  • 2022-12-23
相关资源
相似解决方案