我正在尝试测量当前正在使用 BITS 下载的 ccmcache 目录的递归大小。
我正在使用以下 Powershell 脚本来测量目录的递归大小。
(Get-ChildItem $downloadPath -recurse | Measure-Object -property Length -sum).Sum
此脚本适用于“普通”目录和文件,但如果目录仅包含.tmp
文件,则会失败并出现以下错误。
Measure-Object : The property "Length" cannot be found in the input for any objects.
At line:1 char:27
+ (Get-ChildItem -Recurse | Measure-Object -Property Length -Sum).Sum
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Measure-Object], PSArgumentException
+ FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand
如何测量仅包含.tmp
由 BITS 下载器创建的文件的目录的递归大小。