代码之家  ›  专栏  ›  技术社区  ›  SASPYTHON

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

  •  0
  • SASPYTHON  · 技术社区  · 7 年前

    下午好

    因此,如果我知道哪个文件夹是

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

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

    如何对这种情况进行编码?

    非常感谢

    2 回复  |  直到 7 年前
        1
  •  2
  •   trebleCode    7 年前

    根据您的描述,您似乎只需要将-recurse参数添加到命令中。

        2
  •  1
  •   lit    7 年前

    当 -Recurse 使用开关。使用 -Filter 将阻止查看每个文件。

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