close
Auto Delete Old Files on Windows 10 and 11

There are several people for whom a cluttered desktop & downloads folder is a way of life — no matter how hard you are trying, they will end up disorganized. Do you wanna perform a bit of digital spring-cleaning? You will be glad to know that several ways exist through which you are capable of keeping your Windows 10 PC decluttered. While you are able to get rid of Windows 10 bloatware, you are also capable of sorting the right click menu. In addition, decluttering the search results is possible, along with cleaning up your desktop. Do you want a more passive approach? Then, this article is for you where you will get to know how to auto delete old files on Windows 10 And 11

Pros And Cons Of Auto-Deleting Files:

Like every technology, auto-deleting files also comes with its benefits and drawbacks. Here are some pros and cons that should be considered:

Pros:

  • The most obvious benefit that you can get by setting up an auto-deletion function is that there is no need to manually delete files. So, it helps to save a lot of time as well as your efforts.
  • It prevents your PC from being cluttered with unnecessary files. Thus, it helps you improve system performance.
  • When you delete files automatically, it will help you to decrease the risk level of accidentally leaving sensitive information on your PC.

Cons:

  • Unintentional removal of files is probably a big fear which a person can encounter.
  • You might not have much control over the type of files that you need to auto-delete. As a result, this process can remove the files that you are willing to keep.
  • After the files are deleted, it is hard to retrieve the files.
  • It is challenging to set up auto-deletion rules. And remember, improper configuration may cause issues like unintentional file deletions.

How To Auto Delete Old Files On Windows 10 And 11:

These are the ways through which you can auto delete old files on Windows 10 & 11.

  1. Using Storage Sense:

The easiest process that you can try, if you are a beginner or less tech-savvy user, is to use the Storage Sense feature on Windows computers. This procedure is simple and very easy. You are capable of managing most temporary or downloaded files which have been living under the hood for ages inside the PC.

It is the process through which you can configure Storage Sense:

For Windows 11:

  • If you are a Windows 11 user, you need to navigate to Settings by hitting the Windows Key + I. Then, you should tap on System and Storage.
  • After that, your job is to enable the Storage Sense toggle.
  • Then, your task is to tap on this to configure Storage Sense. Next, your task is to choose the cleanup duration for the Recycle Bin, Storage Sense, & Downloads Folder.
  • You can set the following settings:

Run Storage Sense: Every week

Delete files in recycle bin: Thirty days

Delete files in Downloads folder: Sixty days

Thus, it can delete old files automatically on your computer depending on the timeline which you have set.

Whether you are willing to run the Storage Sense manually, you have to hit the Run Storage Sense Now button. It helps to clear out all the older or temporary files from the Windows PC.

For Windows 10:

  • As a Windows user, you need to press Windows Key + I to launch the Settings app. Then, your task is to go to the System page.
  • Thereafter, you need to move to the Storage section. Now, you have to enable the Storage Sense feature.
  • Next, your task is to tap on the Configure Storage Sense to make adjustments, or you can tap on the Run It Now link.
  • Then, configuring settings is possible as you want.

Similar to Windows 11, whether you are willing to manually run Storage Sense, your task should be to hit the Clean Now button.

  1. Deleted Old Files Or Folders With The Command Prompt:

The Command Prompt is capable of working with simple text-based commands, letting you perform various admin functions & fix different troubleshooting problems on Windows.

Let’s check the below section in order to fix the storage problems through the ForFiles command on Windows:

  • Your first task is to move to the Start menu search bar. Then, you need to type in ‘cmd’. Now, you have to run the CMD as an administrator.
  • In order to delete files which you have not modified in thirty days, you need to type in the following command. After typing the command, you should press Enter:

ForFiles /p “C:\path\to\folder”/s /d -30 /c “cmd /c del /q @file”

  • Hence, “C:\path\to\folder” and /d -30 refer to the folder path from where you are willing to delete files and the specific time when you wish to delete your file. You need to replace these with the settings that are suitable for you.
  • Once you hit the commands, you will see your files are removed.
ForFiles command breakdown:
  • /p — used to indicate the pathname to start searching.
  • /s — it is used for instructing ForFiles to search inside subdirectories.
  • /d — it is used to specify the last modified date for a file.
  • /c — it helps to instruct the ForFiles tool to execute the command. Remember that this one has to be wrapped in double quotes. Hence, “cmd /c del @file” is the default.
  • /q — It lets you delete folders without requiring confirmation.

However, in order to learn more about these switches, your job is to use the ForFiles /? Command.

These are some of the variables that you can use in the command string:
  • @file – it can return the file’s name.
  • @fname – is capable of returning a file name without extension.
  • @ext – can return only the file’s extension.
  • @path – is capable of returning the file’s full path.
  • @relpath – can return the file’s relative path.
  • @isdir – is capable of returning “TRUE” when you see a directory file type, and “FALSE” for files.
  • @fsize – is able to return the file size in bytes.
  • @fdate – is capable of returning the file’s last modified date.
  • @ftime – is able to return the file’s last modified time.
  1. Use Task Scheduler On Windows:

You should know that Task Scheduler is basically a simple Windows tool allowing you to automate your repetitive Windows tasks. Once you set up the task, the app will be able to handle the activity which you have said it to do. Regarding auto-deleting your files or folders, you can use the ForFiles command, which makes the task of deleting your older files or folders a lot easier.

The process you need to follow to automate the deletion is:
  • Your first task is to navigate to the Start menu search bar. Then, you need to choose the best match after typing in ‘task scheduler’.
  • Now, you need to right-click on the Task Scheduler Library. Then, you should choose the option New Folder.
  • You can enter any name and then tap on OK.
  • Next, your task is to right-click on the folder that was created recently. Then, you should choose the Create Task option.
  • Once you see the Name box, you have to put your name for the task.
  • Then, go to the Security options section in the General tab, where you have to choose the Run whether the user is logged on or not option.
  • Ensure that you do not select the Do not store password checkbox.
  • After tapping on the Triggers tab, your job is to choose the New button.
  • Then, you need to use the Begin The Task Setting to choose On A Schedule Option.
  • Now, your job is to set up the timing of every activity you wish to run under the Settings section. Then, you have to tap on OK.
  • Once you go to the Actions tab, your job is to hit the New button. Then, you need to choose the Start a program option from the Actions drop-down menu.
  • Once you see the Program/script box, you have to type in the following command:
ForFiles

Just like this, you have to type in this command in the Add arguments box:

/p “C:\path\to\folder”/s /d -30 /c “cmd /c del /q @file”

  • Hence, you have to tweak the “C:\path\to\folder” to the folder’s path where the files exist. Then, you have to replace “/d -30” with the actual number you want to choose. Therefore, your command will be like this:

/p “%userprofile%\Users\[Your Username]\Downloads” /s /d -30 /c “cmd /c del /q @file”

  • After that, you have to tap on OK. At last, you need to check these checkboxes from the Settings tab. Now, you have to tap on OK.
  • Now, you need to allow the task to be run on demand.
  • Then, you have to run it as soon as possible, once a scheduled start is missed.
  • However, you need to restart all of them if the task fails.
  1. Delete Files Older Than X Days with File Explorer:

This process will let you know how you can delete files older than X days using File Explorer. These are the steps which you need to follow.

Step 1: First, you need to open File Explorer by pressing the Win + E keys.

Step 2: Then, you need to head toward the folder where your files exist. For instance, you can go to the “Downloads” folder.

Step 3: Next, your job is to tap on the Date Modified Dropdowns. After that, your task is to choose a date range according to your requirements. You can see all files in the date range.

Step 4: Now, your task is to select the files which you want to delete. Then, you have to hit the Delete button on the top bar.

  1. Delete Files Older Than X Days With PowerShell:

Do you wish to delete multiple files from different folders & clean up by deleting older than specific days? If this is the case, you obviously want to use PowerShell to delete files which are older than X days. You need to follow these steps to delete files with it:

Step 1: Your first task is to left-click on the Windows main menu button. After that, your job is to look for Windows PowerShell. Then, you need to right-click the result. Now, you should choose Run as administrator.

Step 2: It opens the Windows PowerShell window. Then, you have to type in Get-ChildItem –Path “C:\path\to\folder” -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-X))} |

Remove-Item to delete files which have not been modified in the last few days. Then, you need to tap on Enter. You have to also change the path location: “C:\path\to\folder” with the location of the folder you want to delete. Then, your job is to change -X in order to choose files with the date that is modified last in the above command.

Finally, you need to tap on OK after finalising the changes. And the task does not take too much time. Therefore, you can delete your files automatically within the specified time. If you are willing to change your decision, then delete the new folder made by you simply to reverse the setting.

  1. Using Microsoft PC Manager:

A new tool for Windows 10 and 11 was introduced by Microsoft in 2022, and it is known as Microsoft PC Manager. With the help of the easy-to-use tool, you are able to clean temporary files & manage memory usage. The app includes an option in order to delete temporary files automatically. It helps you to keep the computer free from unnecessary clutter. Follow the below section to know how to do so:

  • Your first task is to download the Microsoft PC Manager app if it’s not downloaded already. Then, you need to open the application.
  • Now, your job is to tap on the Gear/Cog icon. Then, you have to choose the Settings option.
  • Finally, you need to enable the toggle that you can see beside the “PC Manager will automatically boost your PC”.

Because of some bug, the PC Manager could not auto-delete the files. Whenever it happens, you need to clear out the data manually. In order to do so, your job is to tap on the Boost button. Then, you can see the temporary files are deleted instantly from your computer with memory usage.

  1. Delete Files Older Than N Days Using Script:

VBScripts help to delete files that are older than N number of days on a particular folder path. And the VBScripts are available to the Spiceworks forum users. We have given here a simple script:

On Error Resume Next

Set oFileSys = WScript.CreateObject(“Scripting.FileSystemObject”)

sRoot = “C:\Path To Old Files”                                    ‘Path root to look for files

today = Date

nMaxFileAge = 3                                                         ‘Files older than this (in days) will be deleted

DeleteFiles(sRoot)

Function DeleteFiles(ByVal sFolder)

Set oFolder = oFileSys.GetFolder(sFolder)

Set aFiles = oFolder.Files

Set aSubFolders = oFolder.SubFolders

For Each file in aFiles

dFileCreated = FormatDateTime(file.DateCreated, “2”)

If DateDiff(“d”, dFileCreated, today) > nMaxFileAge Then

file.Delete(True)

End If

Next

For Each folder in aSubFolders

DeleteFiles(folder.Path)

Next

End Function

Hence, you get to know from the script that it takes into consideration the “Date Created” property of items rather than “Date Last Modified”. Whether you wish to delete files which have not been modified in the last N days, your task is to change this line in the script:

dFileCreated = FormatDateTime(file.DateCreated, “2”)

to

dFileCreated = FormatDateTime(file.DateLastModified, “2”)

It helps to clear files older than 3 days. Your job in this case is to modify the folder path. Then, you need to max file age parameters in the script as you need. After that, you need to save this file with a .vbs extension & thereafter, your task is to run it. Remember that the script works recursively on the specified folder & sub-folders.

How To Create A Batch File:

You may find creating a batch file too technical or a bit difficult. But there is nothing to worry about as you don’t need to know its meaning.

Hence, your first task will be opening Notepad. Then, you need to copy the following text line and paste this:

forfiles -p “C:\Test” -s -m *.* /D -5 /C “cmd /c del @path”

You will not understand the line, but after going through the explanation, you can know what it indicates. Basically, it asks Windows to delete the files in the C:\Test folder as well as the sub-folders which are older than 5 days.

Test:

Before getting into more details about the command, remember that you have to save the file first. Then, you need to perform a test run. So, first, you have to generate a folder at the root of the C drive on the PC and the folder name is Test. After that, your job is to tap on File – Save. Now, as a batch file, you need to save the file. In order to do so, your job is to type in a name, which is followed by .bat. Next, you need to change the Save as type dropdown to All Files.

Save:

Saving the file is possible in any location on the hard drive you prefer. You have to generate a few dummy files in the Test folder. After that, your job is to double click on the Delete.bat file so that it can run. But still, you will not see anything deleted because the command includes /D -5. The term refers to files which are 5 days or older. When you need to delete any file, regardless of when it was created, you have to change the -5 to -0. Otherwise, your task is removing the /D -5 part altogether. Once you run this, you will see all files deleted.

You have to change the directory to something other than C:\Test to customise the command. It is the first thing which you need to do. It is as easy as copying the path from Windows Explorer for the directory you are willing. Then, you need to paste this into the command in Notepad.

Parameters:

Then, you will see the -s parameter, which can be viewed after the directory path. It means that the command must look into all subfolders. If you are unwilling to delete files from subfolders, you have to remove the -s parameter.

After that, you have to go to -m followed by *.* It indicates that the command has to evaluate every type of file. Whether you are willing to delete a particular file type in a folder, such as JPG images or PDF files, your task is to change *.* to *.pdf or *.jpeg. It can remove only those files.

The /D -X part lets you know how old the files should be to qualify for deletion. You are capable of keeping this with a value greater than 1. Besides, you can set the value to 0, or remove this altogether. And it is everything you should know about the command.

Run:

When you run this command, these are some things which you should note first. You should know that once you delete files, these will be deleted permanently rather than going to the Recycle Bin. Therefore, you need to be aware when you use this. Secondly, the command deletes files only instead of folders.

As it is a batch file, you were able to add the command’s many versions in the same file. For instance, you can make a batch file which will delete all DOCX files that are older than 180 days, PDF files that are older than 60 days & TXT files regardless of how old these are.

Now, you need to create your batch file and save it. Then, you should start scheduling to run on a re-occurring basis.

The Bottom Line:

Always remember that it is seldom useful to keep unnecessary files on your computer. While these consume memory space, these can also clog the file organisation. In addition, they are able to hamper the performance of your computer. You need to set up auto-delete instructions using any process that you prefer. It allows your computer to get rid of the additional baggage.

Before you want to auto-remove files or folders from the PC, remember that this process is a part of cleaning up your Windows. You should know that there are several other crucial hacks like terminating pointless background methods, removing unused apps, & tweaking settings to those which are relevant most to your situation. Therefore, you have to ensure that you are following the best principles to run your Windows as smoothly as you can.

Frequently Asked Questions

How do you delete files older than x days Linux?

Whether you are willing to delete files that are older than X days in Linux, you need to use the command “find /path/* -mtime +X -exec rm -rf {} \;.”. Using the command allows you to find the files. Then, you are able to delete the required file quickly.

Can you recover automatically deleted files on Windows 11?

Deleted files can be recovered automatically on Windows 11. However, if you are willing to recover deleted files on Windows 11, you can take assistance from a reliable third-party data recovery tool.

  • First, you have to launch the recovery software. Then, you need to scan the computer.
  • After that, your job is to preview the deleted files on Windows 11.
  • At last, your task is to recover the files which you want.

How do you remove 30 days old files in UNIX?

First, you have to know the command. After that, it is possible to remove thirty days old files in UNIX. The command which you need to type in is that: find/path/to/the/directory/ -type f -name ‘*’ -mtime +30 -exec rm {} \. After that, you will be able to remove the unwanted files.

Tags : Windows
FileEdge

The author FileEdge