How to delete files older than 30 days with robocopy?

82

I don't know how to do it with robocopy, but when I wanted to do the same as what you're doing, I put this line in my batch file:

forfiles -p %_BACKUPPATH% -m *.rar -d -3 -c "cmd /c del @path"

A dissection is:

  • forfiles - The program for filtering the files
  • -p %_BACKUPPATH% - -p indicates "path" (mine is %_BACKUPPATH% but you can replace this with a "real" path), otherwise it uses the current directory
  • -m *.rar - filter by filetype .rar, skip this parameter for *.*
  • -d -3 - Only affect files older than 3 days (-3)
  • -c "cmd /c del @path" - anything after the -c is what will be executed for each file it finds, in this case, del.
Share:
82

Related videos on Youtube

Rıfat Erdem Sahin
Author by

Rıfat Erdem Sahin

Updated on September 18, 2022

Comments

  • Rıfat Erdem Sahin
    Rıfat Erdem Sahin over 1 year

    We are considering to use the elastic search. But we could not decide if we should use nested objects or plain objects. What are the pros and cons ?

    We have highly schema changed datasource.(hourly)

  • Julio Guerra
    Julio Guerra almost 13 years
    Good to know, but I will delete any file older than 3 days. This in not exactly what I want, I just want to delete files deleted in the src folder since n days.
  • MrGigu
    MrGigu almost 13 years
    @Julio - and I take it the /mir switch isn't doing this for you?
  • Julio Guerra
    Julio Guerra almost 13 years
    No. I synced a new file file first, then I deleted it in the src folder and I ran the previous command with /mir and /minage:30 expecting a "delete files older than 30 days" behavior but it does not.
  • Rıfat Erdem Sahin
    Rıfat Erdem Sahin over 9 years
    if objects are nested it means there are multiple queries to retrieve that object right ?
  • Jettro Coenradie
    Jettro Coenradie over 9 years
    No not really, you can do a nested query to obtain the document. You cannot get back the nested object, only the document containing the nested object. Maybe you mean the parent-child structure also available in elasticsearch
  • Rıfat Erdem Sahin
    Rıfat Erdem Sahin over 9 years
    I need an adaptive system and I also need it fast.