Menu Close

Delete files older than X days

Here’s a quick portion of a PowerShell script I used that will delete files older than X dates from the current date.

Simply change $days to the number of days. In this example, all files older than 7 day will be deleted.

Note that this will only delete the files in the given $path. If you wanted to delete all the sub files/folders in $path, add the -Recurse switch:

Posted in Code, Powershell, Tech

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.