VB.NET,在Windows资源管理器中打开特定文件夹?

Mar*_*vic 22 vb.net

我在Windows资源管理器中打开VB.net中的特定文件夹时遇到问题.我用了

Process.Start("explorer.exe", "Folder_Path")

总是在我尝试这个时它在资源管理器中打开文档,无论我写什么.请帮忙.

Mar*_*vic 40

Process.Start("目录路径")

  • 即使我将路径用双引号引起来,这在 Windows 10 上也会失败,并出现“访问被拒绝”异常。但是,指定“explorer.exe”并将路径作为参数传递(就像所有其他答案一样)是可行的。尽管出现错误,但这与文件夹访问权限无关。 (2认同)

Vin*_*nce 8

尝试打开它:

Process.Start("explorer.exe", "/root,Folder_Path")
Run Code Online (Sandbox Code Playgroud)

或者之前更改路径:

SetCurrentDirectory("Folder_Path")
Process.Start("explorer.exe")
Run Code Online (Sandbox Code Playgroud)

如果仍然失败,请使用shell命令:

Shell("explorer Folder_Path", AppWinStyle.NormalFocus)
Run Code Online (Sandbox Code Playgroud)


pas*_*sty 7

您可以使用这样的预选目录启动资源管理器:

Process.Start("explorer.exe", String.Format("/n, /e, {0}", "d:\yourdirectory\"))
Run Code Online (Sandbox Code Playgroud)

Microsoft 知识库文章中解释了 Windows 资源管理器选项。


Ele*_*ios 5

它仅打开默认目录(MyDocuments)的原因可能是以下两个原因之一:

·该目录不存在。

·目录路径的名称中包含空格,并且包含空格的参数应使用双引号引起来,这是编程的BASIC规则。

然后正确使用语法:

    Dim Proc As String = "Explorer.exe"

    Dim Args As String =
       ControlChars.Quote &
       IO.Path.Combine("C:\", "Folder with spaces in the name") &
       ControlChars.Quote

    Process.Start(Proc, Args)
Run Code Online (Sandbox Code Playgroud)