VB.net文件夹路径不起作用

三亚

在我的代码中,我必须使用通配符“ *”搜索相似的文件夹名称。这段代码在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\00A 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”。确保pathStr存在。

可能您的文件夹包含Unicode字符,请参见此URL C#中的更多内容:System.Diagnostics.Process.Start(“ Explorer.exe”,@“ / select” + FilePath)。文件名是Unicode字符时无法打开文件

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章