tags:

views:

245

answers:

6

How can I convert "c:\foo\..\bar" into "c:\bar"?

+12  A: 
string path = Path.GetFullPath("C:\\foo\\..\\bar"); // path = "C:\\bar"

More Info

Randolpho
+2  A: 

I believe what you're looking for is Syetem.IO.Path as it provides methods to deal with several issues regarding generic paths, even Internet paths.

Paulo Santos
A: 

Not a direct answer, but from the question I suspect you are trying to reinvent the System.IO.Path.Combine() method. That should eliminate the need to create paths like the one you are asking about overall.

Wyatt Barnett
Path.Combine does not resolve "..", it simply concatenates two paths using a single path separator (depending on the platform).
0xA3
+2  A: 

Try System.IO.Path.GetFullPath(@"c:\foo..\bar")

Vasu Balakrishnan
+4  A: 

Have you tried

string path = Path.GetFullPath(@"C:\foo\..\bar");

in C# using the System.IO.Path class?

Colin Desmond
+2  A: 

Use Path.GetFullPath

RichardOD