如何在Powershell中打开文件夹

68

如何在PowerShell中打开文件夹? 我不是在讲述如何在特定文件夹中启动PowerShell。

我的意思是,在powershell的命令行中,我想要打开一个文件夹,例如:"open document"


7
可能是与此问题重复:是否可以从PowerShell打开资源管理器窗口 - manojlds
11个回答

102

使用Invoke-Item命令,或其别名:ii。

PS> ii c:\windows # open the windows directory in windows explorer
PS> ii c:\book.xls # open book.xls in Excel
PS> ii . # open the current directory in windows explorer

36
对于兼容Powershell和cmd的方式(我认为也是最常见的方式):
start .
start c:\

2
不确定是否应该是最常见的 - invoke-item / ii 更具有 PowerShell 风格 :) - x0n
我喜欢这个,它类似于macOS的zsh shell中的“open .”。 - Kris Stern

10

要在Powershell中打开当前文件夹,请输入以下命令:

PS>> explorer.exe $(pwd)


9

使用Invoke-Item,别名ii

ii d:\temp\

6
您可以使用explorer.exe打开文件夹:
explorer.exe c:\temp\
explorer.exe <YourFolderPathHere>

3
只是为了增加一些内容:

还有需要考虑的因素:

PS C:\> ii -path c:\directory\directory\directory

如果您的文件名由两个单词组成并用空格隔开,请考虑使用单引号:

PS C:\> ii -path 'c:\directory\directory\directory directory\'

以下工作[注意-路径是可选项]
   1. ii or invoke-item
   2. explorer.exe
   3. start

3
explorer.exe 后面加上一个点将会打开当前目录:
explorer.exe .

2
我知道这个问题比较老,但是通过谷歌找到这篇文章的人可能仍然会发现它有用:
我创建了一个cmd脚本,其中包含:
@REM Open directory
@REM Version 1.0
@echo off
if [%1]==[] (powershell ii .
    ) Else (
        powershell ii %1
        cd %1
    )

这也可以打开文档,例如文本文件或MS Word文档,以及打开文件夹。

0

在Mac中,输入'open .'将打开当前目录,在Windows PowerShell中输入'start .'也会实现相同的功能。


0

我不太明白你想要什么,但我有两个可能的解决方案:

explorer .\Documents

或者

cd .\Documents

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接