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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22442261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 17:27:54  来源:igfitidea点击:

VB.NET, open specific folder in windows explorer?

vb.net

提问by Marko Stojkovic

I have problem with opening specific folder in VB.net in Windows Explorer. I used

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

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

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

Always when i tried this it open documents in explorer , whatever i wrote. Pls help.

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

回答by Marko Stojkovic

Process.Start("directory path")

Process.Start("目录路径")

回答by Vince

Try opening it with:

尝试打开它:

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

Or change the path before:

或者更改之前的路径:

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

And if it still fails, go with the shell command:

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

Shell("explorer Folder_Path", AppWinStyle.NormalFocus)

回答by ElektroStudios

The reason why it opens the default directory (MyDocuments) only could be one of these two reasons:

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

· The directory does not exist.

· 目录不存在。

· The directory path contains spaces in the name, and arguments containing spaces should be enclosed with doublequotes, this is a BASIC rule of programming.

· 目录路径名称中包含空格,包含空格的参数要用双引号括起来,这是编程的基本规则。

Then use the syntax properrlly:

然后正确使用语法:

    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)

回答by pasty

You could start explorer with preselected directory like this:

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

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

The Windows Explorer options are explained in this Microsoft KB article.

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

回答by Jeremias R??ner

    Process.Start("explorer.exe", "/select," + "C:\File_Name.txt")

The .txt could be what ever u need.

.txt 可能是您所需要的。

回答by Ruby Kousinovali

You can try Process.Start("explorer.exe", "Folder_Path") like you said. The only reason that windows explorer opens the documents folder is that you mistype the "folder_path" and the specified folder doen not exists

您可以像您说的那样尝试 Process.Start("explorer.exe", "Folder_Path") 。windows资源管理器打开文档文件夹的唯一原因是您输入错误“folder_path”并且指定的文件夹不存在