Add Revit cache and temp file cleanup script
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b34ded71bd
commit
8c31cedf35
@@ -0,0 +1,104 @@
|
|||||||
|
#Requires -RunAsAdministrator
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Deletes Revit cache and temp files for all user profiles on the machine.
|
||||||
|
.DESCRIPTION
|
||||||
|
Targets CollaborationCache, UserDataCache, journal files, and Revit-related
|
||||||
|
temp files. Does NOT touch user preferences or settings.
|
||||||
|
#>
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'SilentlyContinue'
|
||||||
|
|
||||||
|
$totalFreed = 0
|
||||||
|
$deletedItems = 0
|
||||||
|
|
||||||
|
function Remove-RevitPath {
|
||||||
|
param(
|
||||||
|
[string]$Path,
|
||||||
|
[string]$Label
|
||||||
|
)
|
||||||
|
if (-not (Test-Path $Path)) { return 0 }
|
||||||
|
|
||||||
|
$sizeBefore = (Get-ChildItem $Path -Recurse -Force -ErrorAction SilentlyContinue |
|
||||||
|
Measure-Object -Property Length -Sum).Sum
|
||||||
|
$sizeBefore = if ($sizeBefore) { $sizeBefore } else { 0 }
|
||||||
|
|
||||||
|
Remove-Item $Path -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
Write-Host " Removed: $Label ($([math]::Round($sizeBefore / 1MB, 2)) MB)" -ForegroundColor Green
|
||||||
|
return $sizeBefore
|
||||||
|
}
|
||||||
|
|
||||||
|
function Remove-RevitFiles {
|
||||||
|
param(
|
||||||
|
[string]$Path,
|
||||||
|
[string]$Filter,
|
||||||
|
[string]$Label
|
||||||
|
)
|
||||||
|
if (-not (Test-Path $Path)) { return 0 }
|
||||||
|
|
||||||
|
$files = Get-ChildItem $Path -Filter $Filter -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
if (-not $files) { return 0 }
|
||||||
|
|
||||||
|
$size = ($files | Measure-Object -Property Length -Sum).Sum
|
||||||
|
$size = if ($size) { $size } else { 0 }
|
||||||
|
|
||||||
|
$files | Remove-Item -Force -ErrorAction SilentlyContinue
|
||||||
|
Write-Host " Removed: $Label ($([math]::Round($size / 1MB, 2)) MB, $($files.Count) files)" -ForegroundColor Green
|
||||||
|
return $size
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "`nRevit Cache Cleaner" -ForegroundColor Cyan
|
||||||
|
Write-Host "===================" -ForegroundColor Cyan
|
||||||
|
|
||||||
|
$userProfiles = Get-ChildItem 'C:\Users' -Directory -ErrorAction Stop |
|
||||||
|
Where-Object { $_.Name -notin @('Public', 'Default', 'Default User', 'All Users') }
|
||||||
|
|
||||||
|
foreach ($profile in $userProfiles) {
|
||||||
|
$userName = $profile.Name
|
||||||
|
$localApp = Join-Path $profile.FullName 'AppData\Local'
|
||||||
|
$localTemp = Join-Path $profile.FullName 'AppData\Local\Temp'
|
||||||
|
|
||||||
|
# Find all Revit version folders (e.g. "Autodesk Revit 2022")
|
||||||
|
$revitLocalBase = Join-Path $localApp 'Autodesk\Revit'
|
||||||
|
$revitVersions = Get-ChildItem $revitLocalBase -Directory -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if (-not $revitVersions) { continue }
|
||||||
|
|
||||||
|
Write-Host "`nUser: $userName" -ForegroundColor Yellow
|
||||||
|
|
||||||
|
foreach ($ver in $revitVersions) {
|
||||||
|
Write-Host " Version: $($ver.Name)"
|
||||||
|
|
||||||
|
# Worksharing / cloud model cache
|
||||||
|
$totalFreed += Remove-RevitPath (Join-Path $ver.FullName 'CollaborationCache') 'CollaborationCache'
|
||||||
|
|
||||||
|
# User data cache
|
||||||
|
$totalFreed += Remove-RevitPath (Join-Path $ver.FullName 'UserDataCache') 'UserDataCache'
|
||||||
|
|
||||||
|
# Crash reports / dump files
|
||||||
|
$totalFreed += Remove-RevitPath (Join-Path $ver.FullName 'CrashReport') 'CrashReports'
|
||||||
|
$totalFreed += Remove-RevitPath (Join-Path $ver.FullName 'RevitCrashFiles') 'RevitCrashFiles'
|
||||||
|
|
||||||
|
# Journal (log) files — keeps folder, deletes contents
|
||||||
|
$journalsPath = Join-Path $ver.FullName 'Journals'
|
||||||
|
$totalFreed += Remove-RevitFiles $journalsPath '*.txt' 'Journal files'
|
||||||
|
|
||||||
|
# Loose .tmp files in the version root
|
||||||
|
$totalFreed += Remove-RevitFiles $ver.FullName '*.tmp' '.tmp files'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Revit-related temp files in %LOCALAPPDATA%\Temp
|
||||||
|
$revitTempPattern = @('Revit_*.tmp', 'acad*.tmp', 'rvt*.tmp', 'Autodesk*.tmp')
|
||||||
|
foreach ($pattern in $revitTempPattern) {
|
||||||
|
$totalFreed += Remove-RevitFiles $localTemp $pattern "Temp\$pattern"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Machine-wide Autodesk temp (some installers/components write here)
|
||||||
|
$machineTemp = 'C:\Windows\Temp'
|
||||||
|
$totalFreed += Remove-RevitFiles $machineTemp 'Revit_*.tmp' 'Windows\Temp Revit files'
|
||||||
|
$totalFreed += Remove-RevitFiles $machineTemp 'Autodesk*.tmp' 'Windows\Temp Autodesk files'
|
||||||
|
|
||||||
|
Write-Host "`n===================" -ForegroundColor Cyan
|
||||||
|
Write-Host "Total freed: $([math]::Round($totalFreed / 1MB, 2)) MB" -ForegroundColor Cyan
|
||||||
|
Write-Host "Done.`n" -ForegroundColor Cyan
|
||||||
Reference in New Issue
Block a user