我尝试找到所有包含$ var并以“.log”结尾的文件,并且我需要将其递归
我试过了
$logDirectoryPath = $Directory + "\*"
Get-ChildItem -Path $logDirectoryPath -Include *$iniContent["Search"]["FileWith"]*, *.log -Recurse -File -Name | ForEach-Object {
$lbox_files.Items.Add($_) # we add file to a list
}
但是此命令返回每个文件,而不管$ var为何,并且Recurse似乎已禁用:/
该文件如下所示:foo_test.log
另一个文件:\ user \ foo_1.log
(PS:$ var,我的意思是它取决于$ iniContent [“Search”] [“FileWith”]的值)
最佳答案
您可以通过以下命令查找所有文件:
Get-ChildItem -Path "c:\" -Recurse -File -Filter "*$var*.log"
它返回文件夹中所有名称为$var
并以".log"
结尾的文件
关于powershell - 如何在Powershell中以递归模式查找包含字符和扩展名的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60656250/