views:

845

answers:

1

Hi, I am writing a VB .NET console app where it spits takes relative path and spits out all file name, or error for invalid input. I am havinf trouble getting PhysicalPath from RelativePath

Example: ` 1. I am in folder: C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj\bin\Debug

  1. My App SP.exe is also in the same folder

  2. I run: "SP.exe ..\" OutPut will be a list of all files in the folder of "C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj\bin"

  3. I run: "SP.exe ..\..\" OutPut will be a list of all files in the folder of "C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj"

  4. I run: "SP.exe ..\..\..\" OutPut will be a list of all files in the folder of "C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol" `

Currently I am Handling 1 relative path, but not more than one:

    If Source.IndexOf("..\") = 0 Then
        Dim Sibling As String = Directory.GetParent(Directory.GetCurrentDirectory()).ToString()())
        Source = Source.Replace("..\", Sibling)
    End If

How can I easily handle multiple ..\ easily ? Thanks.

+4  A: 

You're looking for System.IO.Path.GetFullPath(). It should handle any type of relative path.

shf301
+1, Beat me to it! :)
Zach Johnson
Thanks, It worked!
Mehdi Anis
@Mehdi: Since this looks like it was the solution to your problem, it would be a good idea to mark it as the answer using the checkmark on the left next to the up/down arrows.
Zach Johnson
@Zach Johnson: Thanks for showing the CheckMark (TickMark Icon to accept an answer. I didn't know, icon apperas in gray feels like inactive.
Mehdi Anis