我正在所有的文件夹中查找一个文件。
Copyforbuild.bat在很多地方都有,我想递归搜索。
$File = "V:\Myfolder\**\*.CopyForbuild.bat"
如何在PowerShell中做到这一点?
我正在所有的文件夹中查找一个文件。
Copyforbuild.bat在很多地方都有,我想递归搜索。
$File = "V:\Myfolder\**\*.CopyForbuild.bat"
如何在PowerShell中做到这一点?
当前回答
要向@user3303020添加答案并将搜索结果输出到文件中,可以运行以下命令
Get-ChildItem V:\MyFolder -name -recurse *.CopyForbuild.bat > path_to_results_filename.txt
这样可能更容易搜索正确的文件。
其他回答
当搜索文件夹时,你可能会得到一个基于安全性的错误(例如C:\Users),使用以下命令:
Get-ChildItem -Path V:\Myfolder -Filter CopyForbuild.bat -Recurse -ErrorAction SilentlyContinue -Force
Windows系统: 搜索'c:\temp'目录下的所有。py文件,输入:dir -r *.py或dir *.py -r
*Nix (Linux / MacOs系统: 在终端类型:find /temp -name *.py
这对我来说很好。
Get-ChildItem V:\MyFolder -name -recurse *.CopyForbuild.bat
也可以
要向@user3303020添加答案并将搜索结果输出到文件中,可以运行以下命令
Get-ChildItem V:\MyFolder -name -recurse *.CopyForbuild.bat > path_to_results_filename.txt
这样可能更容易搜索正确的文件。
使用通配符过滤:
Get-ChildItem -Filter CopyForBuild* -Include *.bat,*.cmd -Exclude *.old.cmd,*.old.bat -Recurse
使用正则表达式进行过滤:
Get-ChildItem -Path "V:\Myfolder" -Recurse
| Where-Object { $_.Name -match '\ACopyForBuild\.[(bat)|(cmd)]\Z' }