在我的代码中,我必须使用通配符" *"搜索simliar的文件夹名称。此代码在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)
我仍然得到相同的结果
答案 0 :(得分:1)
资源管理器将转到默认文件夹&#39;我的文档&#39;,如果您尝试打开的文件夹不在那里。确保pathStr存在。
您的文件夹可能包含Unicode字符,请参阅此网址C#: System.Diagnostics.Process.Start("Explorer.exe", @"/select" + FilePath). Can not open file when file's name is unicode character
中的更多内容System.Diagnostics.Process.Start(&#34; Explorer.exe&#34;,&#34; / select,&#34;&#34;&#34;&amp; pathStr&amp;&#34; &#34;&#34;&#34)