Relative path to absolute path in VB.NET
You're looking for System.IO.Path.GetFullPath(). It should handle any type of relative path.
Mehdi Anis
Updated on July 05, 2022Comments
-
Mehdi Anis almost 2 years
I am writing a VB.NET console application where it takes relative paths and spits out all file names, or an error for invalid input. I am having trouble getting PhysicalPath from relative path
Example:
I am in folder
C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj\bin\Debug
My application,
SP.exe
, is also in the same folder.I run:
"SP.exe ..\"
. The output will be a list of all files in the folder"C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj\bin"
I run:
"SP.exe ..\\..\"
. The output will be a list of all files in the folder"C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj"
I run:
"SP.exe ..\\..\\..\"
. The output will be a list of all files in the folder"C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol"
Currently I am handling one relative path, but no more:
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
..\
? -
Zach Johnson about 14 years@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.
-
Mehdi Anis about 14 years@Zach Johnson: Thanks for showing the CheckMark (TickMark Icon to accept an answer. I didn't know, icon apperas in gray feels like inactive.