Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to mirror a folder, but only delete files in the destination folder older than 7 days.


  • Folder A is mirrored to Folder B.
  • A file from Folder A is deleted

I would like for that file to remain in Folder B for 7 days. After 7 days the file would be deleted if it still does not exist in Folder A.

Current solution – in a batch file:

  • Use robocopy with the /mir and /xx option to mirror Folder A to Folder B each day
  • Use Delage32 to delete files and empty folders older than 7 days.

The problem is files (those I want to keep) are constantly being deleted and rewritten daily.

Is there a way to have the mirroring process look for extra files in the destination directory, and only delete them if they are older than 7 days? I would like to eliminate delage32.

share|improve this question

migrated from Dec 16 '12 at 19:07

This question came from our site for professional and enthusiast programmers.

I suggest find on Linux and find's -mtime options.

share|improve this answer
Thanks for the response. I've used Linux a bit, but currently use Windows 7. Any methods for Windows? – user1905482 Dec 16 '12 at 3:49
This really beongs in in many ways. Look at Powershell. Umm....remembering spell: gci . -Recurse -name – ArrowInTree Dec 16 '12 at 3:52

You must log in to answer this question.