【问题标题】:How can I use Windows cmd to find a folder path using where?如何使用 Windows cmd 使用 where 查找文件夹路径?
【发布时间】:2022-01-30 03:37:38
【问题描述】:

我使用的是 Windows 10。“C:\Users\username\AppData\Local\Programs\Microsoft VS Code”中有一个“Microsoft VS Code”文件夹,我想在 cmd 中使用 where 找到它。

现在,我不能 100% 确定文件夹名称,所以我想搜索“[也许在此之前的内容]VS Code”、“VS Code”或“VSCode”,均不区分大小写。

在正则表达式中,应该是/VS\s?Code$/i,如preg_match("/VS\s?Code$/i", "Microsoft VS Code")

如何在where /R C:\ <pattern> 中编写这种简单的模式?
我不能在模式中使用 "" 或 '' 将 "VS Code" 括起来,并且空格被认为是 VS.?Code 会说一个可选空间吗?

所以我的问题是:

  • where 只能找到文件路径,我怎样才能让它也找到文件夹路径?
  • 如何编写搜索模式?

【问题讨论】:

  • 或者,您可以使用 PowerShell 中 Get-ChildItem cmdlet 提供的 -FilterGet-ChildItem -Path "c:\path" -Filter "*vs*code*" -Directory -Recurse
  • 你说你想在 cmd 中使用where ......那就是where.exe。所以...这和powershell有什么关系?
  • PS C:\WINDOWS\system32> Get-ChildItem -Filter *VS?Code -Directory 不返回任何内容,PS C:\WINDOWS\system32> Get-ChildItem -Path "c:\path" -Filter "*vs*code*" -Directory -Recurse 返回对路径 xxx 的访问被拒绝
  • 您输入的是实际路径,而不是“c:\path”吗?否则,请尝试-Force。如果这也无济于事,听起来像是权限问题;建议确保您以管理员身份运行。
  • where.exe是用来在%PATH%中找可执行文件的,不是找文件的工具

标签: windows powershell cmd command-line


【解决方案1】:

where 是一个 exe,而不是 PowerShell 命令

在 powershell 中使用以下内容:

Get-ChildItem -Path "c:\" -Filter "*vs*code*" -Directory -Recurse

您会收到一些错误消息(由于权限问题),您可以通过将c:\ 更改为您想要的路径来修复它们。

【讨论】:

  • 在 Windows 中,(在问题标题中特别提到,并在问题正文中进行了版本化)where.exe 是一个内置的可执行实用程序。作为命令行界面实用程序,它将在命令提示符或 PowerShell 提示符中工作。它可能不是 PowerShell 内置 cmdlet,(更准确),但没有技术原因导致它无法在 Windows PowerShell 会话中运行。
  • where.exe 等价于Get-Command,而不是Get-ChildItem -Recurse 等价于dir /s
  • 其实whereWhere-Object在PowerShell中的别名。 where.exe 命令可以在 PowerShell 中使用,但必须指定 .exe。更好的是,指定%__APPDIR__%where.exe
猜你喜欢
  • 2010-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-02
  • 1970-01-01
  • 2014-02-06
  • 1970-01-01
相关资源
最近更新 更多