【发布时间】:2011-02-05 02:01:57
【问题描述】:
我正在编写一个 VB.NET 控制台应用程序,它采用相对路径并吐出所有文件名,或者无效输入的错误。我在从相对路径获取 PhysicalPath 时遇到问题
例子:
我在文件夹
C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj\bin\Debug我的应用程序
SP.exe也在同一个文件夹中。我运行:
"SP.exe ..\"。输出将是文件夹"C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj\bin" 中所有文件的列表
我运行:
"SP.exe ..\\..\"。输出将是文件夹"C:\Documents and Settings\MehdiAnis.ULTIMATEBANGLA\My Documents\Visual Studio 2005\Projects\SP_Sol\SP_Proj" 中所有文件的列表
我运行:
"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
如何轻松处理多个..\?
【问题讨论】:
标签: .net path relative-path absolute-path