Thursday, April 27, 2023

Cleanup the "Temp" folder!

Over time, the c:\Users\%USERNAME%\AppData\Local\Temp\ folder will collect Gigs and Gigs of files from software. It's best to clean it from time to time but make sure there is not anything useful in this folder before deleting. Once it's gone, it's gone. I am not responsible for anything that is deleted. You can navigate to the folder to manually delete the files and folders or create a batch file to delete the files and folder with just double click. I execute the file about once a month to clean the Temp folder.

Here are the steps to create the batch file.

  1. Open Notepad.
  2. Copy and paste the script below into the blank Notepad file.
  3. Click File then SaveAs.
  4. Click the "Save as type" pull down to select All Files. This will allow the Notepad file to have another file extension type.
  5. Name the file to your preference with a .bat extension. I named the file "Delete User Temp Files.bat".
  6. Execute the batch file. You'll see Command Prompt screen appear as it's deleting the files and folders. It will not delete files and folders that are currently being utilized by the OS or open software.

rem This batch file deletes files

rem and folders in the User Temp folder

cd\

c:

cd c:\Users\%USERNAME%\AppData\Local\Temp\

del /s /q c:\Users\%USERNAME%\AppData\Local\Temp\

rmdir /s /q c:\Users\%USERNAME%\AppData\Local\Temp\

cd\





1 comment:

  1. I have followed the approach to monitor the size of the temp folder. As our startup code launches, it runs this batch file:

    powershell.exe -command "(Get-ChildItem -Path $env:Temp -Recurse -Force | Measure-Object -Sum Length).Sum /1gb | out-file "c:\bce\2018user\tempfoldersize.txt" -Encoding ascii

    That gets reported to a central location so I can see whose temp folder is oversize, and take steps to fix it.

    This tip and more in my AU proposal: https://www.autodesk.com/autodesk-university/conference/submission/effortlessly-manage-your-cad-computers-using-autolisp-and-powershell-data

    ReplyDelete