$ErrorActionPreference='Stop' $dir=$env:TEMP if(-not (Test-Path -LiteralPath $dir -PathType Container)){throw 'Brak katalogu TEMP.'} [int]$days=14 $val=Read-Host 'Pliki tymczasowe starsze niż ile dni? [14]' if($val.Trim() -and (-not [int]::TryParse($val,[ref]$days) -or $days -lt 1)){throw 'Nieprawidłowa liczba dni.'} $files=@(Get-ChildItem -LiteralPath $dir -File -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-$days) -and $_.FullName.StartsWith($dir,[StringComparison]::OrdinalIgnoreCase)}) $sum=($files | Measure-Object Length -Sum).Sum Write-Host "TEMP: $($files.Count) starych plików, około $([math]::Round($sum/1MB,1)) MB." -ForegroundColor Yellow $files | Sort-Object Length -Descending | Select-Object -First 20 FullName,Length | Format-Table -AutoSize Write-Host 'Pliki używane przez aplikacje mogą nie dać się usunąć. Wyłącznie prywatny folder TEMP użytkownika.' if((Read-Host 'Aby bezpowrotnie usunąć pliki, wpisz USUN') -cne 'USUN'){return} [int]$n=0 foreach($item in $files){try{Remove-Item -LiteralPath $item.FullName -Force -ErrorAction Stop;$n++}catch{}} Write-Host "Usunięto $n / $($files.Count)." -ForegroundColor Green