C# Filepath Recasing

前端 未结 6 1553
青春惊慌失措
青春惊慌失措 2020-12-29 06:37

I\'m trying to write a static member function in C# or find one in the .NET Framework that will re-case a file path to what the filesystem specifies.

Example:

<
6条回答
  •  甜味超标
    2020-12-29 06:50

    You can search for the file you want to get the case on and return the results of your search (you want to check the casing of a file that exists, right?). Something like this:

    public static string GetProperFilePathCapitalization(string filepath) {
       string directoryPath = Path.GetDirectoryName(filepath);
       string[] files = Directory.GetFiles(directoryPath, Path.GetFileName(filepath));
       return files[0];
    }
    

    Is this what you're looking for?

提交回复
热议问题