C # Canonical File Names

How to get the name of a canonical file non-canonical.

eg. I want to call a function that converts "C:\Program files\..\Windows\aaa.txt" to "C:\Windows\aaa.txt"

I am looking for something like Java File.getCanonicalPath ()

+6
source share
3 answers

You can use the Path.GetFullPath method for this.

Example:

 Console.WriteLine(Path.GetFullPath(@"C:\Program files\..\Windows\aaa.txt")); 

Conclusion:

C: \ Windows \ aaa.txt

+13
source
 System.IO.Path.GetFullPath("C:/Program files/../Windows/aaa.txt") 

will return

 "C:\\Windows\\aaa.txt" 
+3
source

Here is my suggestion:

 string path = Path.GetFullPath(@"C:\Program files\..\Windows\aaa.txt"); 
+1
source

Source: https://habr.com/ru/post/901286/


All Articles