我正在学习PowerShell,并在Technet上看到了这样的用法:
Test-Path -Path $DirectoryPath -PathType 'Leaf'路径类型Leaf的含义是什么?
很清楚Container和Any路径类型是什么。
发布于 2018-01-15 11:50:27
来自Test-Path帮助:
-PathType <TestPathType>
Specifies the type of the final element in the path. This cmdlet returns $True if the element is of the specified
type and $False if it is not. The acceptable values for this parameter are:
- Container. An element that contains other elements, such as a directory or registry key. - Leaf. An element that
does not contain other elements, such as a file. - Any. Either a container or a leaf. Tells whether the final
element in the path is of a particular type.具体地说:
-Leaf。不包含其他元素(如文件)的元素。
从控制台获取这些信息的最简单方法是Get-Help Test-Path -Parameter PathType。
发布于 2018-01-15 11:53:36
如果您看到相同的PowerShell文档,这将是明确的。使用以下命令
Get-Help Test-Path -Full
如果您查看Test-Path支持的所有参数的描述,您将看到-PathType参数,该参数如下
-PathType <TestPathType>
Specifies the type of the final element in the path. This cmdlet returns $True if the element is of the
specified type and $False if it is not. The acceptable values for this parameter are:
- Container. An element that contains other elements, such as a directory or registry key. - Leaf. An element
that does not contain other elements, such as a file. - Any. Either a container or a leaf. Tells whether the
final element in the path is of a particular type.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false因此,-container是指目录、文件夹或子文件夹,而leaf是指文件.如果需要更多帮助,也可以使用Get-Help Test-Path -Examples查看示例
发布于 2021-08-30 22:11:52
一般来说:
Leaf:文件Container:文件夹/目录Any:文件或文件夹。
隐喻是,您的文件系统就像一个树层次结构,每个分支节点要么能够进一步分支(文件夹),要么是一个不能进一步分支的叶节点(文件)。
举例说明:

https://stackoverflow.com/questions/48262339
复制相似问题