How can I obtain the case-sensitive path on Windows?

后端 未结 8 622
慢半拍i
慢半拍i 2020-12-01 18:00

I need to know which is the real path of a given path.

For example:

The real path is: d:\\src\\File.txt
And the user give me: D:\\src\\file.txt
I nee

8条回答
  •  一整个雨季
    2020-12-01 18:24

    As an old-timer, I always used FindFirstFile for this purpose. The .Net translation is:

    Directory.GetFiles(Path.GetDirectoryName(userSuppliedName), Path.GetFileName(userSuppliedName)).FirstOrDefault();
    

    This only gets you the correct casing for the filename portion of the path, not then entire path.

    JeffreyLWhitledge's comment provides a link to a recursive version that can work (though not always) to resolve the full path.

提交回复
热议问题