Search code examples
c#pathcase-sensitive

Check path case sensitivity


I am trying to convert paths to a canonical form in order to compare them. I'm almost there but I'm stuck with the casing :

If the paths are not case sensitive (i.e. on Windows), my final step should be something like path = path.ToUpper() or ToLower(). On other systems (i.e. Linux, OSX), this final step should be skipped.

Is there a proper way to detect this ?


Solution

  • You are probably looking for System.Environment.OSVersion. This will detect the version of windows as well. So if you want then you can simply check if the version is Windows then do the casing else skip it.

    Something like

    System.OperatingSystem osInfo = System.Environment.OSVersion;
    if(osInfo .Contains("Windows"))
    {
      //Do casing
    }
    else
    {
      //skip
    }