我正在所有的文件夹中查找一个文件。
Copyforbuild.bat在很多地方都有,我想递归搜索。
$File = "V:\Myfolder\**\*.CopyForbuild.bat"
如何在PowerShell中做到这一点?
我正在所有的文件夹中查找一个文件。
Copyforbuild.bat在很多地方都有,我想递归搜索。
$File = "V:\Myfolder\**\*.CopyForbuild.bat"
如何在PowerShell中做到这一点?
当前回答
Windows系统: 搜索'c:\temp'目录下的所有。py文件,输入:dir -r *.py或dir *.py -r
*Nix (Linux / MacOs系统: 在终端类型:find /temp -name *.py
这对我来说很好。
其他回答
使用带有-递归开关的Get-ChildItem cmdlet:
Get-ChildItem -Path V:\Myfolder -Filter CopyForbuild.bat -Recurse -ErrorAction SilentlyContinue -Force
试试这个:
Get-ChildItem -Path V:\Myfolder -Filter CopyForbuild.bat -Recurse | Where-Object { $_.Attributes -ne "Directory"}
Get-ChildItem V:\MyFolder -name -recurse *.CopyForbuild.bat
也可以
当搜索文件夹时,你可能会得到一个基于安全性的错误(例如C:\Users),使用以下命令:
Get-ChildItem -Path V:\Myfolder -Filter CopyForbuild.bat -Recurse -ErrorAction SilentlyContinue -Force
使用通配符过滤:
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' }