JPB*_*anc 56
如果您对隐藏文件或系统文件不感兴趣,也可以使用Test-Path
要查看目录中.\temp是否存在文件,您可以使用:
Test-Path -Path .\temp\*
Run Code Online (Sandbox Code Playgroud)
或者很快:
Test-Path .\temp\*
Run Code Online (Sandbox Code Playgroud)
Boe*_*ckm 45
试试这个...
$directoryInfo = Get-ChildItem C:\temp | Measure-Object
$directoryInfo.count #Returns the count of all of the objects in the directory
Run Code Online (Sandbox Code Playgroud)
如果$directoryInfo.count -eq 0,则您的目录为空.
Mui*_*ota 15
为了防止枚举c:\ Temp下的每个文件(这可能很耗时),我们可以做这样的事情:
if((Get-ChildItem c:\temp\ -force | Select-Object -First 1 | Measure-Object).Count -eq 0)
{
# folder is empty
}
Run Code Online (Sandbox Code Playgroud)
filter Test-DirectoryEmpty {
[bool](Get-ChildItem $_\* -Force)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
65686 次 |
| 最近记录: |