VB.NET中绝对路径的相对路径

Meh*_*nis 12 .net path relative-path absolute-path

我正在编写一个VB.NET控制台应用程序,它采用相对路径并吐出所有文件名,或者输出无效错误.我无法从相对路径获取PhysicalPath

例:

  1. 我在文件夹中 C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj\bin\Debug

  2. 我的应用程序SP.exe也在同一个文件夹中.

  3. 我跑:"SP.exe ..\".输出将是文件夹中所有文件的列表"C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj\bin"

  4. 我跑:"SP.exe ..\\..\".输出将是文件夹中所有文件的列表"C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj"

  5. 我跑:"SP.exe ..\\..\\..\".输出将是文件夹中所有文件的列表"C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol"

目前我正在处理一个相对路径,但不再:

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

我怎样才能轻松处理多个..\

shf*_*301 24

您正在寻找System.IO.Path.GetFullPath().它应该处理任何类型的相对路径.