Cross-platform file name handling in .NET Core

前端 未结 6 1445
我在风中等你
我在风中等你 2020-12-15 03:02

How to handle file name in System.IO classes in a cross-platform manner to make it work on Windows and Linux?

For example, I write this code that works

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 03:32

    The original post is over a year old but I still ran into this issue. It seems to me like the use of dots in relative paths is also an issue.

    A path like

    ".\\input\\mydata.csv" 
    

    worked well on windows but not on unix. When changing the dot-notation for current directory to:

    Path.GetFullPath(Directory.GetCurrentDirectory())
    

    I had more success.

提交回复
热议问题