我想使用Get-Children命令的-Depth参数来查找与下面显示的两个文件同名的较浅文件。"Original Answer"翻译成"最初的回答"。
许多帖子建议将-Path定义为"C:\temp\"或"C:\temp\\*"。但在我的情况下,我更喜欢使用-Depth参数来限制搜索中递归的深度。我已经阅读了它意味着递归,因此不需要与recurse一起使用。到目前为止,我尝试了下面所有的命令,但它们都返回下面进一步显示的相同结果。"最初的回答"
所有上述命令产生的结果都相同,即"最初的回答"。
C:\temp\test.txt
C:\temp\Logs\test.txt
许多帖子建议将-Path定义为"C:\temp\"或"C:\temp\\*"。但在我的情况下,我更喜欢使用-Depth参数来限制搜索中递归的深度。我已经阅读了它意味着递归,因此不需要与recurse一起使用。到目前为止,我尝试了下面所有的命令,但它们都返回下面进一步显示的相同结果。"最初的回答"
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 | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth $d -Include tes*.txt | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth $d -Include tes*.txt -Recurse | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth 0 -Include tes*.txt -Recurse | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth 0 -Include tes*.txt -Recurse | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth 2 -Include tes*.txt -Recurse | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Depth 3 -Include tes*.txt -Recurse | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Include tes*.txt -Depth 1 | Format-List -Property FullName
Get-ChildItem -Path C:\temp -Include tes*.txt -Depth 0 | Format-List -Property FullName
Get-ChildItem -Path C:\temp -File -Include tes*.txt -Depth 0 | Format-List -Property FullName
Get-ChildItem -Path C:\temp -File -Include tes*.txt -Depth 1 | Format-List -Property FullName
Get-ChildItem -Path C:\temp -File -Include tes*.txt -Depth 2 | Format-List -Property FullName
Get-ChildItem -Path C:\temp\* -Include tes*.txt -Recurse | Format-List -Property FullName
所有上述命令产生的结果都相同,即"最初的回答"。
FullName : C:\temp\Logs\test.txt
FullName : C:\temp\test.txt
除了使用-Depth属性外,像许多人建议的那样使用"\*"可以使我隔离出更深的文件,但不能隔离出更浅的文件。我有什么遗漏吗?
除了使用-Depth属性,像许多人建议的那样使用"\*"可以使我隔离出更深的文件,但不能隔离出更浅的文件。您是否还有其他问题?
PS C:\> Get-ChildItem -Path C:\temp\* -Include tes*.txt -Recurse | Format-List -Property FullName
FullName : C:\temp\Logs\test.txt
FullName : C:\temp\test.txt
PS C:\> Get-ChildItem -Path C:\temp\*\* -Include tes*.txt -Recurse | Format-List -Property FullName
FullName : C:\temp\Logs\test.txt
PS C:\> Get-ChildItem -Path C:\temp\*\*\* -Include tes*.txt -Recurse | Format-List -Property FullName
PS C:\>
\*\*
符号时,你可以跳过“较浅”的文件夹。 - undefined-Depth
参数必须与-Recurse
参数一起使用,并且禁止使用-Include
和-Exclude
参数。 - undefined