How to get canonical file name by non-canonical one.
E.g. I want to call function which converts "C:\Program files\..\Windows\aaa.txt"
to "C:\Windows\aaa.txt"
I am looking for something like Java File.getCanonicalPath()
How to get canonical file name by non-canonical one.
E.g. I want to call function which converts "C:\Program files\..\Windows\aaa.txt"
to "C:\Windows\aaa.txt"
I am looking for something like Java File.getCanonicalPath()
You can use the Path.GetFullPath
method for this.
Example:
Console.WriteLine(Path.GetFullPath(@"C:\Program files\..\Windows\aaa.txt"));
Output:
C:\Windows\aaa.txt
System.IO.Path.GetFullPath("C:/Program files/../Windows/aaa.txt")
will return
"C:\\Windows\\aaa.txt"
Here is my suggestion:
string path = Path.GetFullPath(@"C:\Program files\..\Windows\aaa.txt");