+3 votes
274 views
Delete old files automatically from a Windows 10 folder

in Windows 10 by (552k points)
reopened | 274 views

1 Answer

+4 votes
Best answer

1. How to delete old files in Windows 10 using ForFiles
2. How to delete files using Windows PowerShell
3. Delete old files with the Windows 10 task scheduler

Hard disk space is a sensitive issue since if our hard disk has limited space, its behavior may soon be affected when it is full, a full disk causes:

  • System lock or its applications
  • Errors reading and writing information
  • Slowness in the process of opening or saving information

As users we must be aware that many times we forget to delete the files, and many are large. That is why Microsoft has decided to give us a hand and has integrated the storage sensor function which can delete temporary files, files and objects in the recycle bin or in the Downloads library in a time range. The limit of this is that it acts on files that have not undergone any change in the last 60 days, but if there are older files, what happens there? The following will explain how to delete old files using various methods in Windows 10..


1. How to delete old files in Windows 10 using ForFiles


This is a command that selects and executes a command directly in a file a set of them and is ideal for batch processing.
Step 1

Its use syntax is as follows:
 forfiles [/ p <Route>] [/ m <Search_parameter>] [/ s] [/ c "<Command>"] [/ d [{+ | -}] [{<Date> | <Days>}]] 
The parameters described are:
/Route
Indicates the path from which the search will originate which by default starts in the current working directory

Search_parameter
This option searches files based on a specific search mask, the search mask by effect is *. \ *.

/ s
This value instructs the forfiles command to search subdirectories recursively.

/ c
Execute the command indicated in each file

/ d & # 91
⁠ [{| ⁠}] '] Allows you to select files using a last modification date as a criterion, we can choose files with a last modification date after or equal to (+) or before or (() the specified date, this format must be MM / DD / AAA and valid values ​​for days are any number in the range 0–32,768
Step 2

To use this command we access the command prompt as administrators and there we will execute the following command which will delete the files that have not been used in the last 50 days:
 ForFiles / p "D: \ Personal \ Excerpts" / s / d -50 / c "cmd / c from @file" 
image
Step 3

There we must confirm this action with the letter S, the current content of that folder is:

image

Step 4

Press Enter to confirm the action: image
Step 5

Now the folder will be like this:

image


2. How to delete files using Windows PowerShell


The Windows PowerShell console is one of the simplest options for deleting files in a previous time range.
Step 1

For this we must use the following syntax in PowerShell as administrators:
 Get-ChildItem –Path "Route" -Recurse | Where-Object {($ _. LastWriteTime -lt (Get-Date) .AddDays (-30))} | Remove-Item 
Note
The value 30 can be edited for the desired number of days.
Step 2

For this case we will delete the files that have not undergone changes in the last 60 days:
 Get-ChildItem –Path "D: \ Aliexpress" -Recurse | Where-Object {($ _. LastWriteTime -lt (Get-Date) .AddDays (-60))} | Remove-Item 
The content of the folder is:

image

Step 3

When executing the command we must confirm the action: image
Step 4

Enter the letter S and press Enter to validate the action: image
Step 5

Our folder will now look like this:

image


3. Delete old files with the Windows 10 task scheduler


The task scheduler is an integral tool to tell Windows 10 to execute certain tasks and one of them can undoubtedly be deleting old files.
Step 1

To use this method, we access the programmer using the Windows + R keys and executing the taskschd.msc command. Once there we will right click on “Task Scheduler Library” and select the “New folder” option: image
Step 2

We assign an appropriate name to this:

image

Step 3

Click OK to confirm the action, now, select this folder, right click somewhere free and select “Create new task”: image
Step 4

We assign a name to this task and check the “Execute whether user login or not” box:

image

Note
The “Do not store password” box must be disabled.
Step 5

We go to the "Triggers" tab. We click on New.

image

Step 6

In the "Start the task" field, select "According to a schedule" and then define the days or months in which this task will be executed:

image

Step 7

Click on OK to save the changes and now go to the "Actions" tab:

image

Step 8

Click on New and in the "Action" field select "Start a program", in the "Program / Script" field enter ForFiles and in the "Add arguments" field enter the following:
 / p "D: \ TechnoWikis" / s / d -50 / c "cmd / c from @file" 
Step 9

Note: there we enter the path in which the files will be deleted and indicate the number of days.

image

Step 10

We click OK to save the changes:

image

Step 11

Now we go to the "Configuration" tab and there we define that the following is active:
  • Allow the task to run on request
  • Execute the task as soon as possible, if there was no scheduled start
  • If the task is not executed, restart it every time and indicate the times of this.

image

Step 12

We click on Accept and the following pop-up window will appear where we enter the user password:

image

We click on Accept and in this way this task has been programmed to delete the files according to the given conditions.
With these simple methods we can delete files regardless of the day they are not in use in Windows 10.


by (3.5m points)
edited

Related questions

+4 votes
1 answer
asked Nov 6, 2019 in Windows 10 by backtothefuture (552k points) | 820 views
+5 votes
1 answer
asked Sep 20, 2019 in Windows 10 by backtothefuture (552k points) | 283 views
+4 votes
1 answer
+5 votes
1 answer
asked Mar 5, 2020 in Windows 10 by backtothefuture (552k points) | 1.9k views
+4 votes
1 answer
asked Apr 27, 2020 in Windows 10 by backtothefuture (552k points) | 587 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users