0

I need to remove files older than 30 days under builds\<BuilnNumber>\workflow\*.*. I also need to remove files older than a year under builds\<BuilnNumber>\htmlreports\*.*, if they exist.

How do I do that?

I tried using FOR /D /r %%G in ("*") DO xxxx %%~nxG, but got stuck there.

Compo
  • 36,585
  • 5
  • 27
  • 39
OkyDokyman
  • 3,786
  • 7
  • 38
  • 50
  • Yes but I need a removal under builds\\workflow, and not builds\\other_directory – OkyDokyman Feb 03 '21 at 10:51
  • So change the value of the `-p` option to what you need. You also don't mention `other_directory` at any point in your question. – SomethingDark Feb 03 '21 at 10:55
  • Perhaps you could turn to [[tag:powershell]] for your task, you could even do that from a [[tag:batch-file]]. I prefer using PowerShell, especially for the case of your older than one year stipulation, where you shouldn't be assuming a specific number of days, for example: `…| Where-Object {$PSItem.LastWriteTime -LT (Get-Date).AddYears(-1)} |…`. As an example of your thirty days threshold, you'd change your filtering accordingly, e.g. `…| Where-Object {$PSItem.LastWriteTime -LT (Get-Date).AddDays(-30)} |…`. _You can even exchange `LastWriteTime`, with `CreationTime` according to your needs_. – Compo Feb 03 '21 at 13:30

0 Answers0