检查 CSV 是否为空

Amr*_*rma 3 powershell powershell-4.0

我有一个只有一列的 CSV 文件。

**Fruits**
Apple
Orange
Run Code Online (Sandbox Code Playgroud)

如何检查此 csv 是否为空,我的意思是 csv 文件中是否没有列出苹果或橙子。

我使用以下代码导入 csv,但我不确定在执行进一步命令之前如何在导入后检查 csv 是否为空。

$path     = Split-Path -parent $MyInvocation.MyCommand.Definition
$csvPathforFruits = $path + "\Fruits.csv"
$importFruit = Import-Csv $csvPathforFruits
Run Code Online (Sandbox Code Playgroud)

les*_*ode 5

怎么样:

$importFruit = @(Import-Csv $csvPathforFruits)    
$importFruit.Length -gt 0
Run Code Online (Sandbox Code Playgroud)

True如果 CSV 中有任何非标题行,则会返回此值。