0

i'm strugling to create a Batch file sript to: - delete files - 'older than N days' - 'of specific filetypes' - 'contain specific words in filename'

For examle i want to delete files from path "c:\test" - older than 30 days - that are type of ".dmp" and ".log" - and they contain the words "aaa" or "bbb" in the filename.

I've tried some variation of this link but didn't succeed.

Community
  • 1
  • 1
lefteris
  • 1
  • 1
  • Some hints to delete files older than N days can be found at http://ss64.com/nt/syntax-delolder.html. I am using their method 3) successfully. – Melebius Oct 20 '15 at 10:37
  • Yes indeed, but i want certain filetypes and filenames..and i can't put all that arguments in search mask of "forfiles /m.." – lefteris Oct 20 '15 at 10:49
  • Where is the proplem? Simply use `forfiles` command 4 times to delete all files older than 30 days with the patterns `*aaa*.dmp`, `*bbb*.dmp`, `*aaa*.log` and `*bbb*.log` in your batch file. – Mofi Oct 20 '15 at 11:17
  • I've Never thought it like that..! i was stack with the for command.. Thanks #mofi i used forfiles 4 times and worked.. – lefteris Oct 20 '15 at 11:32

1 Answers1

1

The following deletes files from directory C:\test, which match the pattern *aaa*.dmp and are at least 30 days old.

forfiles /P "C:\test" /M "*aaa*.dmp" /D -30 /C "cmd /C del @path"

Subdirectories are not searched; if you want that too add switch /S.

aschipfl
  • 33,626
  • 12
  • 54
  • 99