Perhaps you know the problem that your files, pictures, videos etc. are taking up more and more space on your hard drive and that there will have to be a cleanup at some point. Here it would be good if there was a possibility that after creating a backup, all the files that are older than ??? will be deleted. Days.
Unfortunately, neither the “DEL” command nor Windows Explorer has this function by default. To do this, there are endless tools on the Internet that do this work for you. But it is also easier, because with a single command you can delete the files recursively through all subdirectories. We will show you exactly how this works here below.
As an example, we have a directory that contains 15 different Word files, some of which are older than 1 year , as you can see here.
Of the 15 files shown, 7 are older than 365 days , i.e. 1 year. The subdirectory also contains 6 files, all of which are older than 1 year. We will now delete all these files with the following command.
There are 2 variants of the command, the first shows the files to be deleted in the command prompt so that you can check this again. The 2nd command then deletes the actual files.
Show files older than ??? Days
With this command, you first display the files that are older than the number of days that you specify.
ForFiles / p “PATH INFORMATION” / s / m *. * / D -365 / c “cmd / c echo @file ”
Delete files older than ??? Days
And with this command you delete the files that are older than the specified days.
ForFiles / p “PATH INFORMATION” / s / m *. * / D -365 / c “cmd / c del @file”
In the command prompt it looks like this:
With the parameter “/ d” you can transfer the number of days . All files that are ” OLDER ” than the specified days will then be deleted . This is also done in the folder below, so the command goes recursively through all subdirectories and deletes the files there too.
ATTENTION: If this creates empty subdirectories, these are not deleted by the command! In addition, you should definitely perform a complete data backup before issuing the command !
After deletion, the directory looks like this:
Of course, you can also change the command by removing the “/ S” parameter , then the subdirectories will not be edited and the older files will remain there.
If you are interested in further articles on the topic of “deleting files”, we recommend the following articles:
– Activate security question when deleting files under Windows 10 (registry)
– Delete temporary files automatically in Windows 10
– Delete list of recently used files in Windows 10 taskbar
– Merge and delete Hyper-V Snapshot .AVHD files
– Delete temporary Internet files via desktop shortcut
– Deactivating deletion confirmation when deleting files / folders
– CIPHER – Deleting files / folders safely
– Program icons in the taskbar disappeared in Windows 10
– Delete icon cache – Deactivating the thumbnail cache in Windows 10