powershell - 如何在Powershell中以递归模式查找包含字符和扩展名的文件?

标签 powershell file include filenames file-extension

我尝试找到所有包含$ 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/

相关文章:

c++ - 强制 C++ 使用本地头文件中的函数

c# - 如何访问从 Powershell 的 .NET 事件返回的对象参数

powershell - 在本地运行时,Invoke-Command是否在当前作用域或子作用域中运行?

file - this.$refs.selectedImages.files.map 不是一个函数 - vue electro

c++ - 未正确考虑 Makefile 中的依赖项

python - 在 python bindings/clang 中的 get-includes 中解析 cpp 文件时过滤目录

Powershell - 在 Readline 上使用 Peek 方法是否有好处(虽然不为空)?

powershell - 为什么这个 powershell 或过滤器不起作用?

c# - SaveFileDialog 上的自定义检查文件名

python - 带套接字的 TCP 客户端/服务器、服务器向客户端发送文件、客户端挂起、Python