VB.NET中相对路径与绝对路径
我正在编写一个 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"
I 中所有文件的列表运行:
“SP.exe ..\\..\”
。输出将是我运行的 所有文件的列表
中所有文件的列表,“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
如何轻松处理多个 ..\
?
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 ..\
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找 System.IO.Path.GetFullPath()。它应该处理任何类型的相对路径。
You're looking for System.IO.Path.GetFullPath(). It should handle any type of relative path.