我正在学习PowerShell并且已经在Technet上看到了这个:
Test-Path -Path $DirectoryPath -PathType 'Leaf'
路径类型Leaf
的含义是什么?
很清楚Container
和Any
路径类型是什么
答案 0 :(得分:3)
如果您看到相同的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
答案 1 :(得分:1)
来自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