Create a Batch File to Clear the Cache
-
Open Notepad:
Press Win + R, typenotepad
, and hit Enter. -
Enter the Script:
Copy and paste the following commands into Notepad. This script will delete all files and folders in your temporary folder:@echo off echo Clearing cache... REM Delete files in the temp folder del /q /f "%temp%\*" REM Delete folders in the temp folder for /d %%p in ("%temp%\*") do rmdir "%%p" /s /q echo Cache cleared.
A little note: This script targets the Windows temporary folder (which is generally safe). Always double-check to make sure this is what you want to clear.
-
Save the File:
Click File > Save As and set the following:- File name:
clear_cache.bat
- Save as type: All Files (.)
- Location: For example, you can create a folder like
C:\Scripts
and save it there.
Then click Save.
- File name:
Create a Scheduled Task
-
Open Task Scheduler:
Press Win + S, type Task Scheduler, and press Enter. -
Create a Basic Task:
- In the Task Scheduler window, click on Create Basic Task... in the right-hand pane.
- Name and Description:
- Name: Clear Cache Daily
- Description: (Optional) Something like “Clears the temporary cache every day.”
- Click Next.
-
Set the Trigger:
- Trigger: Select Daily.
- Start Date and Time: Choose the day and time you’d like the task to run (for instance, when you’re unlikely to be actively using the PC).
- Click Next.
-
Set the Action:
- Action: Choose Start a program.
- Program/script:
- Click Browse... and navigate to where you saved your
clear_cache.bat
file (e.g.,C:\Scripts\clear_cache.bat
).
- Click Browse... and navigate to where you saved your
- Click Next.
-
Finish the Wizard:
Review your settings and click Finish.
(Optional) Run with Elevated Privileges
Sometimes deleting files in system directories requires administrative privileges. To ensure the task runs smoothly:
- In Task Scheduler, locate your newly created task in the Task Scheduler Library.
- Right-click on the task and choose Properties.
- Under the General tab, check the box that says Run with highest privileges.
- Click OK.
Test the Task
- In Task Scheduler, right-click your task and select Run.
- Observe if a command prompt window appears and the script executes. You should see the messages “Clearing cache…” and “Cache cleared.”
Comments