我想知道如何在目录中显示空文件列表
$test = gci "C:\Users\Freedom\Documents" -Recurse
$test | Where-Object {$_.PsISContainer} | Select-Object FullName | Where-Object {$_.GetFiles() -eq 0}
我不明白,因为当我做get-childitem | get-member
我得到一个属性和方法列表,我可以使用,在列表中是getfiles()
为什么我不能使用这种方法为什么它给我一个错误信息?
Method invocation failed because [System.IO.FileInfo] does not contain a method named 'GetFiles'.
我想你想要这个:
Get-ChildItem | Where-Object { (-not $_.PSIsContainer) -and ($_.Length -eq 0) }
如果您有PowerShell 3.0或更高版本,您可以使用:
Get-ChildItem -File | Where-Object { $_.Length -eq 0 }
当然你可以为你想要的Get-ChildItem
添加任何其他参数(-Recurse
等)。
哇我有我想要的混合!我不得不将.count
添加到getfiles()
方法中
$test | Where-Object {$_.PsISContainer} | Where-Object {$_.GetFiles().Count -eq 0} | Select-Object FullName
试试这个
Get-ChildItem "c:\temp" -File -Recurse | where Length -eq 0
使用Get-ChildItem
和File
标志,需要-Recurse
来获取文件夹和下面的文件夹中的每个文件。然后获取所有文件,Get-Content
返回null。
Get-ChildItem $YourPath -Recurse -File | Where-Object {!(Get-Content $_.Fullname)}