How to Create Batch File to Delete Temp Files Windows 10

Do you need to delete temporary files to free up space on Windows PC? Follow this post to see how to create a batch file to delete temp files Windows 10 as well as get an easier way to delete temp files without difficulty.

Posted by @Hedy December 17, 2024 Updated By @Hedy May 12, 2023

Temp files take up too much space! Delete them now!

"I am one who likes to keep my computers clean and running smoothly. All my files/folders etc are super organized and tidy. I'm wondering whether I can create a batch file to delete temp files Windows 10. Can I set this batch file to run each time at startup? Any suggestion is appreciated."

Temporary files are used to store temporary data and are created by Windows itself or the programs that users use. These files not only help the computer run smoothly when processing related programs or tasks but also help create a recovery backup in case your system or program shuts down suddenly.

Most of the temp files are deleted automatically after the task is finished, but there are some files that still exist for future use. If you don't delete them, they keep taking up space on your hard drive. As more and more temp files accumulate, you will find you are short of disk space and even your PC gets slower and slower.

In order to free up space, the following content will show you how to clean up them from using Windows 10 batch file to delete temp files and employing a professional PC cleaner.

How to create batch file to delete temp files Windows 10 automatically?

If you are not willing to clean up the temporary files every single time, you can write a batch script to delete temp files Windows 10. When you start up your PC, this batch file will help you delete temporary files automatically.

Step 1. Press "Windows + R" keys together to open the Run dialog box, type Notepad and hit the "Enter" key, or click "Ok" to launch Notepad.

Step 2. Copy and paste the following code into the newly opened Notepad file.

rd %temp% /s /q

md %temp%

Step 3. Hit the "Ctrl + S" keys at the same time, or click on the File tab at the top and choose the "Save as" option. In the new window, choose "Save as type" as All files and copy paste the following path and file name.

%appdata%\microsoft\windows\start menu\programs\startup\cleantemp.bat

Note: This operation will create your batch file and save it inside the Startup folder. Each time the system boots up, this batch file will be woken up and begin to clean up your temporary files automatically. Please note that files in use will not be deleted.

Step 4. If you want to delete this batch script from the start-up, you can copy and paste the path %appdata%\microsoft\windows\start menu\programs\startup in Windows file explorer and delete it.

Another automatic way: Activate Storage Sense to delete temp files Windows 10

If you are not a computer technician or not confident in writing the right batch file to delete temp files Windows 10, you can try another automatic cleaning program to help you clear temporary files in Windows 10. Microsoft provides a new option in the Storage sense to automatically delete temp files that are not used. Follow the below steps to have a try:

Step 1. Press the "Windows + I" key simultaneously to open the Settings window and then click “System”.

Step 2. On the left side of the window, go to "Storage".

Step 3. On the right side, the Storage Sense should be enabled by default, if it's not, you can turn on Storage Sense by activating its switch.

Step 4. Under the Storage Sense switch, there's a link called "Configure Storage Sense or run it now." To change how Storage Sense works regularly on your Windows 10, click on it to continue.

Step 5. On the "Configure Storage Sense or run it now" page, go to the Temporary Files sector, tick “Delete temporary files that my apps aren’t using” and change the time to 1 day, 14 days, or 60 days based on your needs.

PC cleaner: Replace batch file to delete temp files Windows 10 safely and quickly

In addition to activating storage sense and creating a batch file to delete temp files, I highly recommend you use a professional and practical PC cleaner called AOMEI Partition Assistant Standard which is compatible with all editions of Windows 11/10/8/7/XP and Vista.

AOMEI software can not only scan and remove temporary files from your Windows computer but also delete other types of junk files like registry files, log files, and so on. With a graphic and clear interface, you can delete these useless files easily and securely.

Download FreewareWin 11/10/8.1/8/7/XP
Secure Download

Tip: You can also free up space by deleting large files or moving apps/folders to another drive after upgrading to the Professional edition.

Step 1. Install and launch AOMEI Partition Assistant Standard, and then click "Free up" > "PC Cleaner".

Step 2. In the pop-up window, click "Start Scan" to scan for junk files.

Step 3. Wait until the scanning process completes.

Step 4. After the scan is completed, all kinds of available junk files will be listed. Then, tick the options you want to clean, then click "Clean All" to begin the cleaning process.

Step 5. When you see a correct symbol displayed in the interface, you can click "Back" to exit the Window.

Conclusion

Windows always generate temp files and other junk files that are consuming up space on your hard drive. In this passage, we've covered how to create a batch file to delete temp files Windows 10, activate Storage Sense to remove temp files regularly, and use a powerful PC cleaner to delete all kinds of junk files.

It's no doubt that AOMEI software is more versatile both in deleting temporary files and other aspects such as migrating OS to SSD, allocating free space, cloning HDD to SSD, and more.