Script to Delete Files Older Than 7 Days

Today, I created the folders X and Y. Files in folder X that will be precisely 7 days old from now forth should be transferred from X to folder Y after 7 days, and so on. How to do that?

Best Answered by

Dany· Answered on Jan 17, 2023

Actually, the command lines to move the files older than 7 days are similar with delete files older than x days. Run your CMD on your computer, and type in forfiles /p [source_path] /m *.* /s /d [-x_days] /c "cmd /c move @file [destination_path]". You should change "source_path" to the folder path which you want to move all the files recursively. Also need to change "x_days" to "7_days". "destination_path" means the folder path where you want to move all the files. It is possible to schedule this command with other automated tasks, which can be saved as a .bat file.

If you accidentally delete some files or move the files to somewhere you cannot find, you can use a data recovery utility to get back the lost files. EaseUS Data Recovery Wizard can help you do that quickly and safely. Unlimited data may be recovered from deleted, hidden, and lost files. RAW partition recovery is also supported by this utility. You can retrieve the lost files within three steps:

1. After preparing the software, you can launch it and scan the target hard drive or partition where your lost files are located. This software also supports SD card recovery, memory card recovery, and external hard drive recovery.

2. The files will show up during the scanning, and you can choose the files you want to recover in this step.

3. The last part is previewing the files and recovering them. You will only need to press the "Recover" button, and all the selected files will be recovered immediately.

Use EaseUS Data Recovery Wizard to recover deleted or lost files easily and quickly.

Tutorials on how to recover lost, deleted, or formatted data from HDD, SSD, USB, SD card, or other storage media on Windows and Mac.

People Also Ask

How to Fix Windows 8.1 System Files Not Accessible on Computer

It looks like your system files are deleted or corrupted. Don't be frustrated. Since you can open CMD, you can fix the problem with the CMD. We will show you how to do that.


Jan 11, 2023

How to Delete Files Older Than 30 Days with PowerShell

You can delete files older than 30 days with PowerShell, and there are other solutions to delete these files. We will introduce all the possible ways in this passage.


Jan 06, 2023

Accidentally Deleted Large MKV File, How to Recover

MKV videos that have been lost or destroyed can be recovered using the third-party best video recovery software. We will introduce the best solution to assist you in recovering deleted MKV videos using powerful Video recovery software - EaseUS Data Recovery Wizard in the following article.


Jan 13, 2023

How to Recover Deleted Files from SD Card Using Chrome OS

SD cards are widely used due to their high data transfer speed and hot-swappable features, although various data loss issues plague them. Don't panic if you accidentally delete files from your SD card; different recovery methods and SD recovery software can help you retrieve deleted files from your SD card.


Dec 29, 2022

How to Delete Files Older Than 90 Days and Save A Copy

You may free up space and keep things organized by only deleting files in any folder that is older than a specific number of days. If you have many files in separate directories and want to clear them up by eliminating those older than a particular number of days, you can use the ForFiles command.


Jan 11, 2023

Quickly Delete Massive File Structure on Windows Server 2012

Normally, the deletion of large files takes a long time. Your computer needs to confirm and analyze the data, which will take time. The methods below may help you quickly delete massive files structure on Windows Server 2012.


Jan 10, 2023