从 PowerShell 中目录中的特定文件夹获取文件

v_k*_*mar 3 powershell powershell-3.0 powershell-4.0

我的一个目录中有 4 个文件夹。所有这些文件夹都包含一些文件。我只想列出两个文件夹中的文件名。

C:\MainFolder\FolderOne\FileOne.txt
C:\MainFolder\FolderTwo\FileTwo.txt
C:\MainFolder\FolderThree\FileThree.txt
C:\MainFolder\FolderFour\FileFour.txt
Run Code Online (Sandbox Code Playgroud)

我只想列出FolderTwo 和FolderThree 下的文件。

如果我使用-Recurse -Include "FolderNames"它,它只会列出文件夹名称。

jri*_*der 6

$source="c:\MainFolder" #location of starting directory
$files=@("*.txt", "*.doc") #if you want to include extensions add -include ($files) to get-ChildItem

Get-ChildItem -recurse ($source) -File | Where-Object {$_.PSParentPath -match "Two|Three"}
Run Code Online (Sandbox Code Playgroud)