To clean up a folder on a regular basis, you can configure Windows to automatically delete all files and folders in a folder. Here’s how.
In Windows, deleting files in a folder is as easy as selecting all of them and then pressing the DELETE key. However, if you want to automatically delete all files in a folder then the story will be different. You have to go through some hoops to get the job done.
Recently, I received an email from a WL user asking me a way to automatically delete all the files and folders in a folder on schedule. Coincidentally, I’ve been doing that for many years now with my Screenshots folder. To be more precise, I sync my Screenshots folder with OneDrive and configured Windows Task Scheduler to delete all files in the Screenshot folder as soon as I log into the system. Since all the files are already synced with OneDrive, there is no data loss. It just cleans the clutter. You can do that same with any folder you want.
So, without further ado, let me show the way you can automatically delete all files in a folder on schedule in Windows.
Note: I’m showing this in Windows 10 but you can follow the same steps in Windows 7 and 8. Also, don’t confuse the below method with Storage Sense feature in Windows 10. Storage Sense will only clean/delete files in system folders like Downloads, temp, etc. You cannot assign custom folders to it.
Recommended: How to Automatically empty recycle bin in Windows
Delete All Files Automatically in a Folder
Since Windows has no simple way to automatically delete all files and folders in a folder, you need to create a batch script to get the job done. After creating that, you can use the task scheduler to execute the batch script on a schedule.
1. The first thing we need to do is create a batch script aka, .bat file. To do that, right-click on the desktop and select “New → Text Document“.
2. This action will create a new text file. Name the text file as “AutoDelete.bat“. You can name the file anything you want. Just make sure that you replace .txt extension with .bat.
3. After creating the .bat file, right-click on it and select the “Edit” option. This option will open the file in your default text editor, Notepad. In the Notepad, copy and paste the below code. Replace the dummy path with the actual folder path.
set folder="D:\replace\dummy\folder\path" cd /d %folder% for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
4. Save the file by pressing the Ctrl + S keyboard shortcut or by selecting the “File → Save” option. After saving, close the file.
5. After creating the file, use the Task Scheduler to schedule the batch file. I’ve already written a detailed step by step guide on how to do it. Do follow the article and you will be done.
In case you are wondering, all the files and folders deleted from the target folder will still be available in the Recycle Bin. This makes it easy to restore them if need be.
I hope that helps. If you are stuck or need some help, comment below and I will try to help as much as possible.