windows 如何从 cmd.exe 在给定目录中打开资源管理器窗口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3400884/
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
How do I open an Explorer window in a given directory from cmd.exe?
提问by Robert Karl
I see how to launch many other programsfrom a batch file, but I can't find a command like open
on Mac OS X. Does such a tool exist on Windows? Powershell, or a Windows API call from an executable would also work.
我看到如何从批处理文件启动许多其他程序,但我找不到像open
Mac OS X 这样的命令。 Windows 上是否存在这样的工具?Powershell 或来自可执行文件的 Windows API 调用也可以使用。
回答by Leniel Maccaferri
In Windows you can open Explorer with the following command:
在 Windows 中,您可以使用以下命令打开资源管理器:
C:\Users\Leniel>start %windir%\explorer.exe
If you want it to open a specific folder, do this for example:
如果您希望它打开特定文件夹,请执行以下操作,例如:
C:\Users\Leniel>start %windir%\explorer.exe "C:\Users\Leniel\Desktop"
回答by Joey
The direct equivalent of OS X's open
is start
in cmd
.
的OS X的直接相当于open
是start
在cmd
。
start foo.txt
would launch Notepad (or whatever text editor you're using),
将启动记事本(或您使用的任何文本编辑器),
start http://example.com
would launch your browser,
会启动你的浏览器,
start \someDirectory
will launch Explorer, etc.
将启动资源管理器等。
Care has to be taken with arguments in quotes, as start
will interpret the first quoted argument as the window title to use, so something like
必须注意引号中的参数,因为start
会将第一个带引号的参数解释为要使用的窗口标题,因此类似于
start "C:\Users\Me\Folder with spaces\somedocument.docx"
will not work as intended. Instead prepend an empty quoted argument in that case:
不会按预期工作。在这种情况下,而是在前面加上一个空的引用参数:
start "" "C:\Users\Me\Folder with spaces\somedocument.docx"
Note that start
isn't a separate program but a shell-builtin. So to invoke this from an external program you have to use something like
请注意,这start
不是一个单独的程序,而是一个 shell 内置程序。所以要从外部程序调用它,你必须使用类似的东西
cmd /c start ...
The equivalent in PowerShell is either Start-Process
or Invoke-Item
. The latter is probably better suited for this task.
PowerShell 中的等效项是Start-Process
或Invoke-Item
。后者可能更适合这项任务。
Invoke-Item foo.txt # launches your text editor with foo.txt
Invoke-Item . # starts Explorer in the current directory
As for the Windows API, you're looking for ShellExecute
with the open
verb.
至于Windows的API,你正在寻找ShellExecute
与open
动词。