VB.net 文件夹路径无效

VB.net Folder Path not working

在我的代码中,我必须使用通配符“*”来搜索相似的文件夹名称。此代码在 VBA 中运行良好(Process.Start ... 行除外),但它现在所做的只是打开我的文档。

应该是打开一个网络文件夹。

字符串pathStr产生了最终的文件夹路径,这是正确的

我已经对文件夹路径进行了三重检查(我复制了此代码生成的内容并粘贴到 Windows 资源管理器中,然后检查了路径)

为什么我的代码只打开我的文档?

Private Sub OpenJobToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenJobToolStripMenuItem.Click
    Dim jobnum As String = ListView1.SelectedItems(0).Text

    'Define the master path to all job numbers
    Dim masterpath As String = "\ussatf02\Production[=11=]A Job Folders\"

    'Get the child folder path
    Dim fullFolder As String = masterpath & jobnum.Substring(0, 5) & "xxx\"

    'Get first 8 characters of job number
    Dim jobFolder As String = jobnum.Substring(0, 8)

    'Define the full path to the jobFolder
    Dim xPath As String = fullFolder & jobFolder

    'Check the full path with a wildcard to see if there is a folder named something simliar to what we have
    Dim foundFolder As String = Dir(xPath & "*", vbDirectory)

    'If the folder is not found (length < 2) then throw an error, else open the folder
    If (foundFolder.Length < 2) Then
        Dim msgRes As MsgBoxResult = MsgBox("The job folder for: " & jobnum & " could not be found.", vbCritical, "Error Finding Folder")
    Else

        'Define the final path of the folder
        Dim pathStr As String = xPath & "\" & foundFolder

        'Open the folder
        System.Diagnostics.Process.Start("explorer.exe", pathStr)
    End If

End Sub

任何帮助将不胜感激!!

编辑

我现在替换了行

 Dim pathStr As String = xPath & "\" & foundFolder

为了

 Dim pathStr As String = System.IO.Path.GetDirectoryName(xPath & "\" & foundFolder)

我仍然得到相同的结果

在这种情况下 'My Documents' 如果您尝试打开的文件夹不存在,Explorer 将转到默认文件夹。确保 pathStr 存在。

可能您的文件夹包含 Unicode 字符,在此查看更多内容 URL C#: System.Diagnostics.Process.Start("Explorer.exe", @"/select" + FilePath). Can not open file when file's name is unicode character

System.Diagnostics.Process.Start("Explorer.exe", "/select,""" & pathStr & """)