如何检查大文件?

时间:2014-07-04 15:35:41

标签: powershell if-statement

我试图这样做,但不起作用,任何想法?

if(Test-Path ~\desktop){

    $bigfiles = Get-ChildItem ~\desktop -force -Include *.* | Where-Object {$_.Length -gt 10GB}

    if{$bigfiles -gt 10GB){

        echo "You have big files"
    }
}

这是错误:

Cannot compare "C:\Users\mario\Desktop\AngelinaJolie_photo_in_4k.jpg" because it is not IComparable.
At line:7 char:8
+     if($bigfiles -gt 10GB){
+        ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NotIcomparable

1 个答案:

答案 0 :(得分:3)

如果没有结果,$ bigfiles为$ null,如果有一个结果,则为FileInfo,否则为FileInfo的数组。您可以使用

检查结果
if($bigfiles) { ... }