在我的代码中,我必须使用通配符“*”来搜索一个类似文件夹的名称。这段代码在VBA中工作得很好(Process.Start ...
行除外),但现在它只是打开“我的文档”。VB.net文件夹路径不工作
它应该打开一个网络文件夹。
字符串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)
我仍然得到同样的结果
您为xPath获得了什么价值? –
@TonyDong我得到:'\\ ussatf02 \ Production \ 00A Job Folders \ 21643xxx \ 21643043'。问题是有些员工会在文件夹末尾添加额外的字符(例如,重命名文件夹:21643043 - 我的客户) - 所以我必须发出通配符搜索。 – Sanya
你能找到foundFolder吗? –