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
I tried to avoid dll imports so the best way for me was to use System.Linq and the System.IO.Directory class.
For your example Real path is: d:\src\File.txt The user give me: D:\src\file.txt
Code for this:
using System.Linq;
public static class PathUtils
{
public static string RealPath(string inputPath)
{
return Directory.GetFiles(Path.GetDirectoryName(inputPath))
.FirstOrDefault(p => String.Equals(Path.GetFileName(p),
Path.GetFileName(inputPath), StringComparison.OrdinalIgnoreCase));
}
}
var p = PathUtils.RealPath(@"D:\src\file.txt");
Method should return the path "d:\src\File.txt" or "D:\src\File.txt".