MpakoImageAIbot/scripts/cleanup_comfy_assets.ps1

27 lines
684 B
PowerShell

param(
[string]$ComfyRoot = "C:\ComfyUI",
[int]$RetentionHours = 6,
[switch]$WhatIf
)
$cutoff = (Get-Date).AddHours(-[Math]::Abs($RetentionHours))
$paths = @(
(Join-Path $ComfyRoot "output"),
(Join-Path $ComfyRoot "temp")
)
foreach ($path in $paths) {
if (-not (Test-Path -LiteralPath $path)) {
continue
}
Get-ChildItem -LiteralPath $path -Recurse -File |
Where-Object { $_.LastWriteTime -lt $cutoff } |
ForEach-Object {
if ($WhatIf) {
Write-Output $_.FullName
} else {
Remove-Item -LiteralPath $_.FullName -Force -ErrorAction SilentlyContinue
}
}
}