I need a script that will remove any files older than 30 days from a folder while leaving any files and directories with files within that are younger than 30 days. Any ideas for deleting files older than 30 days with PowerShell or other tools?
Dany· Answered on Jun 30, 2025
To delete files older than 30 days ( we will take Windows 10 as an example), you can use PowerShell, Command Prompt, and File Explorer:
1. Right-click your search result for Windows PowerShell and choose "Run as administrator" after opening the Start menu on Windows 10. Type in Get-ChildItem –Path "C:\\path\\to\\folder" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-30))} | Remove-Item in the window. Replace C:pathtofolder with the folder location containing the files you wish to remove, and change "-30" to the command above that selects files with the latest updated date. Then the command will run after pressing the Enter key.
2. Run Command Prompt as an administrator on your Windows 10. Type in ForFiles //p "C:pathtofolder"//s //d -X //c "cmd //c del //q @file and hit Enter. Change C:pathtofolder to the path to the folder you want to remove files from, and change "//d -X" to the option you wish to use to only choose files with the last updated date. This command will help you delete files older than x days.
3. Delete files older than 30 days with Task Scheduler is the simplest way for novice users. To launch File Explorer, press Win + E on your keyboard and find the target folder. Click "Date Modified", choose the files, and delete them.
If you want to recover deleted files, you can download a third-party recovery tool. It is possible to recover deleted files from Recycle Bin, recent backups, or restore your system to a previous date. With three simple steps, you can try EaseUS Data Recovery Wizard to get back your lost films, Word documents, music, and personal pictures.
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.
How to Recover Data Deleted by Robocopy Command on Windows
While using a Robocoy command or script, enter the wrong path will cause data loss. The best way to recover these files deleted by Robocopy command is to download a data recovery program.
Dany
Dec 12, 2025
Can't Delete Files or Format My SD Card When It's Not Locked
When you cannot delete files on an SD card, it means your SD card is locked or under protection. You can fix this problem by reading the passage below, and we will provide some methods.
Dany
Jun 30, 2025
Fix Sorry We Couldn't Find Your File, Was It Moved, Renamed or Deleted
This post will help solve this; sorry we couldn't find your file. was it moved, renamed, or deleted in several effective ways. Read on!
Finley
Dec 12, 2025
How to Delete the OS from a Hard Drive but Keep the Data
Let us now look at removing Windows OS from a hard drive with retaining the data. In other words, without formatting it. It's also the methods of how to remove and uninstall Windows 7, 8, or 10 from a dual boot PC.
Jaden
Dec 12, 2025
Bak File Recovery Software Free Download
Download the best Bak file recovery software to recover accidentally deleted or corrupted Back files as soon as possible. It's the best way to recover your backup files (.bak file extension) from any device.
Dany
Dec 12, 2025
How to Fix Can't Delete a File That's Stuck on Desktop
There are several methods to delete a file that is stuck on your desktop, and we will show you some possible solutions to help you troubleshoot this problem in this passage.
Dany
Jun 30, 2025