我尝试使用 Get-Children cmdlet 的 -Depth 参数来查找具有相同名称的 2 个文件中较浅(较浅)的文件,如下所示。
C:\temp\test.txt
C:\temp\Logs\test.txt
Run Code Online (Sandbox Code Playgroud)
许多帖子建议将 -Path 定义为“C:\temp\ ”或“C:\temp \\*”。但就我而言,我更喜欢使用 -Depth 参数来限制搜索中递归的深度。我读到它意味着递归,因此不需要与递归结合使用。到目前为止,我已经尝试了下面的所有命令,但它们都返回下面显示的相同结果。
Get-ChildItem -Path C:\temp -Depth 0 -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth 1 -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth 2 -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth 3 -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth '1' -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth "1" -Include tes*.txt | …Run Code Online (Sandbox Code Playgroud)