【发布时间】: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-ChildItemcmdlet 提供的-Filter:Get-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