如何从Powershell文件夹中的多个文件夹中查找特定短语

时间:2019-01-18 18:01:54

标签: powershell

下午好

因此,如果我知道哪个文件夹,则此代码可以找到某些短语

Get-ChildItem -Path 'C:\Users\k1\Desktop\test\New folder'  |Select-String -Pattern "apple"

Desktop\test\New folder\Courses Taught Fac:apple

但是如果在“测试”文件夹中有很多文件夹,但是我不知道其中有哪个文件夹,但是我知道“测试”文件夹中某些文件夹中某些文本文件上的某些短语。

我该如何编码这种情况?

非常感谢您

2 个答案:

答案 0 :(得分:2)

Based on your description it sounds like you just need to add the -Recurse parameter to your command

答案 1 :(得分:1)

Searching through all subdirectories will be done when the -Recurse switch is used. Using -Filter will prevent looking through every file.

Get-ChildItem -Path 'C:\Users\k1\Desktop\test\New folder' -Recurse -File -Filter '*.txt' |
    Select-String -Pattern "apple"