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

发布于 2024-08-27 18:24:59 字数 1063 浏览 4 评论 0原文

我正在编写一个 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. I 中所有文件的列表运行:“SP.exe ..\\..\”。输出将是

  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

如何轻松处理多个 ..\

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:

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

  2. My application, SP.exe, is also in the same folder.

  3. 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"

  4. 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"

  5. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七度光 2024-09-03 18:24:59

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文