Windows

forfiles

DestructiveBatch by file age

forfiles /P <dir> /D -30 /C "cmd /c del @file"

Acts on files by age — the standard 'delete logs older than 30 days' building block.

Examples

  • forfiles /P C:\logs /M *.log /D -30 /C "cmd /c del @path"Delete logs older than 30 days

Syntax

forfiles [/P path] [/M mask] [/D ±days] /C "command"

Before you run it

Pairs with del; dry-run with echo first.

Related commands

Check it once more before you run it

Some commands cannot be undone if one flag is wrong. An on-device reference works with no connection. Free to install, no ads.

Get it free on the App Store