francois P
francois P

Reputation: 392

Power shell how to get list of N biggest files of type text

PowerShell how to get list of N biggest files of type text ?

my goal is exactly to

I spend a bunch of time for doing tries all day long yesterday around things like

 gci -r|sort -descending -property length | select -first 10 name, length

get-childItem .....

-filter and so on but no success but I a m new to powershell so ..

Upvotes: 0

Views: 94

Answers (1)

Theo
Theo

Reputation: 61068

Testing if a file is textual of binary is extremely hard to do, but in Windows you can use the file extensions to filter out what you don't want in the result.

$refDate = (Get-Date).AddDays(-30).Date
# fill the list of binary filetypes that are most likely found
$binaries = '*.exe', '*.bin', '*.png', '*.gif', '*.jpg', '*.dll'  # etcetera

Get-ChildItem -File -Recurse -Exclude $binaries | 
    Where-Object {$_.LastWriteTime -lt $refDate} | 
    Sort-Object Length -Descending |
    Select-Object -First 10 | 
    Select-Object Name, Length   # I would use FullName as you are using recursion..

Of course, you will have to add binary files that pop up in the output to th list in $binaries because I have just put a few examples in there now.

Upvotes: 4

Related Questions