mirror of
https://github.com/ChuckPa/PlexDBRepair.git
synced 2026-02-12 22:16:11 -06:00
Add PhotoTranscoder cleanup to Windows script
This commit is contained in:
33
CleanPhotoCache-Windows.ps1
Normal file
33
CleanPhotoCache-Windows.ps1
Normal 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";
|
||||
}
|
||||
Reference in New Issue
Block a user