Add PhotoTranscoder cleanup to Windows script

This commit is contained in:
danrahn
2024-05-05 17:57:54 -07:00
parent d0084c96fb
commit 690e89cf57
2 changed files with 156 additions and 8 deletions

View File

@@ -0,0 +1,33 @@
param(
[Parameter(Mandatory)]
[String]$cacheDir,
[Int32]$cacheAge=30
);
$cutoff = (Get-Date).AddDays(-$cacheAge);
$allFiles = 0;
$oldFiles = 0;
$freedBytes = 0;
Get-ChildItem -Path $cacheDir -Recurse -File |
where { $_.extension -in '.jpg','.jpeg','.png','.ppm' } |
ForEach {
$allFiles++;
if ($_.LastWriteTime -lt $cutoff) {
$oldFiles++;
$freedBytes += $_.Length;
Remove-Item $_.FullName;
}
};
Write-Output $allFiles;
Write-Output $oldFiles;
if ($freedBytes -gt 1GB) {
Write-Output "$([math]::round($freedBytes / 1GB, 2)) GiB";
} elseif ($freedBytes -gt 1MB) {
Write-Output "$([math]::round($freedBytes / 1MB, 2)) MiB";
} elseif ($freedBytes -gt 1KB) {
Write-Output "$([math]::round($freedBytes / 1KB, 2)) KiB";
} else {
Write-Output "$($freedBytes) bytes";
}