Skip to content

Instantly share code, notes, and snippets.

@etcetra7n
Last active August 2, 2025 20:10
Show Gist options
  • Save etcetra7n/8f4dd3aa00188a437315d667051b8031 to your computer and use it in GitHub Desktop.
Save etcetra7n/8f4dd3aa00188a437315d667051b8031 to your computer and use it in GitHub Desktop.
Compare Sizes across files and folders powershell utility

LsSize Utility

Registry command key:

C:\scripts\singleinstance.exe "%1" "LsSizeLauncher.bat" "$files" --si-timeout 300
param (
[Parameter(Mandatory = $true, ValueFromRemainingArguments = $true)]
[string[]]$Paths
)
function Get-SizeReadable {
param ([Int64]$bytes)
$suffixes = "B","KB","MB","GB","TB","PB"
$i = 0
while ($bytes -ge 1024 -and $i -lt $suffixes.Length - 1) {
$bytes = [math]::Round($bytes / 1024, 2)
$i++
}
return "$bytes $($suffixes[$i])"
}
$dirs = @()
$files = @()
if ($Paths.Count -eq 1) {
$Paths = @(Get-ChildItem -LiteralPath $Paths | Select-Object -ExpandProperty FullName)
}
foreach ($path in $Paths) {
$item = Get-Item $path
if ($item.PSIsContainer) {
$dirs += $path
} else {
$files += $path
}
}
Write-Host ("{0,-32} {1, -15} {2}" -f "Name", "Count", "Size") -ForegroundColor Green
Write-Host ("{0,-32} {1, -15} {2}" -f "----", "-----", "----") -ForegroundColor Green
foreach ($path in $dirs) {
$item = Get-Item $path
$stats = Get-ChildItem -Recurse -File -Path $path | Measure-Object -Property Length -Sum
$sizeFormatted = Get-SizeReadable $stats.Sum
$displayName = Split-Path -Path $path -Leaf
if ($stats.Sum -ge 1073741824){
Write-Host ("{0,-32} {1, -15} {2}" -f $displayName, ("$($stats.Count) files"), $sizeFormatted) -ForegroundColor Red
} else {
Write-Host ("{0,-32} {1, -15} {2}" -f $displayName, ("$($stats.Count) files"), $sizeFormatted) -ForegroundColor Cyan
}
}
foreach ($path in $files) {
$item = Get-Item $path
$sizeFormatted = Get-SizeReadable $item.Length
$displayName = Split-Path -Path $path -Leaf
if ($item.Length -ge 1073741824){
Write-Host ("{0,-32} {1, -15} {2}" -f $displayName, "", $sizeFormatted) -ForegroundColor Red
} else {
Write-Host ("{0,-32} {1, -15} {2}" -f $displayName, "", $sizeFormatted) -ForegroundColor Yellow
}
}
Write-Host
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\CompareSizes]
@="Compare sizes"
"Icon"="F:\\icons\\folder.ico"
[HKEY_CLASSES_ROOT\Directory\shell\CompareSizes\command]
@="C:\\scripts\\singleinstance.exe \"%1\" \"LsSizeLauncher.bat\" \"$files\" --si-timeout 300"
@echo off
powershell -NoProfile -ExecutionPolicy Bypass -File "C:\scripts\LsSize.ps1" %*
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment