我在目录中有4个文件夹。所有这些文件夹都包含一些文件。我想仅从两个文件夹中列出文件名。
C:\MainFolder\FolderOne\FileOne.txt
C:\MainFolder\FolderTwo\FileTwo.txt
C:\MainFolder\FolderThree\FileThree.txt
C:\MainFolder\FolderFour\FileFour.txt
我只想列出FolderTwo和FolderThree下的文件。
如果我使用-Recurse -Include "FolderNames"
,它将仅列出文件夹名称。
答案 0 :(得分:2)
$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"}
答案 1 :(得分:0)
get-childitem -recurse 'foldertwo','folderthree'
答案 2 :(得分:0)
喜欢这个
$arrPath ='C:\MainFolder\FolderTwo','C:\MainFolder\FolderThree'
get-childitem -recurse $arrPath