The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Auto-delete files older than 90 days

To automatically delete files older than 90 days, you can set up a scheduled task or script depending on your operating system. Here are common solutions for Windows, macOS, and Linux:


Windows (Using PowerShell + Task Scheduler)

  1. PowerShell Script:

powershell
$Path = "C:PathToFolder" $Days = 90 $CurrentDate = Get-Date Get-ChildItem -Path $Path -Recurse | Where-Object { ($_.LastWriteTime -lt $CurrentDate.AddDays(-$Days)) -and !$_.PSIsContainer } | Remove-Item -Force
  1. Set Up Task Scheduler:

    • Open Task Scheduler → Create Basic Task.

    • Choose a trigger (e.g., Daily).

    • Select “Start a program” → Browse and select PowerShell.

    • Add arguments:

      powershell
      -ExecutionPolicy Bypass -File "C:PathToScript.ps1"

Linux/macOS (Using a Cron Job)

  1. Shell Command:

bash
find /path/to/folder -type f -mtime +90 -exec rm -f {} ;
  1. Add to Cron:

    • Run crontab -e and add:

      bash
      0 2 * * * find /path/to/folder -type f -mtime +90 -exec rm -f {} ;
    • This runs daily at 2 AM.


Notes:

  • Replace /path/to/folder or C:PathToFolder with your actual folder path.

  • Test scripts on sample directories first to prevent accidental data loss.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About