本文介绍了限制 Get-ChildItem 递归深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用此命令递归获取所有子项:

I can get all sub-items recursively using this command:

Get-ChildItem -recurse

但是有没有办法限制深度?例如,如果我只想向下递归一两级?

But is there a way to limit the depth? If I only want to recurse one or two levels down for example?

推荐答案

使用这个将深度限制为 2:

Use this to limit the depth to 2:

Get-ChildItem \*\*\*,\*\*,\*

它的工作方式是在每个深度 2,1 和 0 处返回子项.

The way it works is that it returns the children at each depth 2,1 and 0.

说明:

这个命令

Get-ChildItem \*\*\*

返回深度为两个子文件夹的所有项目.添加 \* 会添加一个额外的子文件夹进行搜索.

returns all items with a depth of two subfolders. Adding \* adds an additional subfolder to search in.

根据 OP 问题,要使用 get-childitem 限制递归搜索,您需要指定可以搜索的所有深度.

In line with the OP question, to limit a recursive search using get-childitem you are required to specify all the depths that can be searched.

这篇关于限制 Get-ChildItem 递归深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:57
查看更多