Robocopy file deletion - files 7 days or older

Posted on 2011-05-09
Last Modified: 2012-06-21
I'm trying to setup a robocopy job that will delete all files on a drive with a modified date of seven or more days and write a log of the deletions.

I'm trying this on Windoed 2003 & Windows 2008

Post an example with the switch definitions.
Question by:Tony Giangreco
    LVL 25

    Author Comment

    by:Tony Giangreco
    This is a real life question.
    LVL 31

    Expert Comment

    On Robocopy, you can use the /move switch to move files and directories rather than copying them (as opposed to /mov, which does not remove emptied directories) thus deleting it from your source.  If starting at a root, you will need to include the /s switch to include sub-directories (excluding empty ones). The /xn switch will exclude files newer that the date listed.  To create a logfile, use the /log: command switch.  Thus:

    robocopy <sourceroot> <destination path> *.* /s /move /xn <date> /log:<filename>

    Does that make sense?

    LVL 25

    Author Comment

    by:Tony Giangreco
    Yes that makes sense. is there another utility that works well that might do exactly what I want in an automated manner?
    LVL 31

    Accepted Solution

    Not that I am aware of.  In the past, I worked with a DBA who was also very good with VBScript.  He wrote a script which, when ran (from the scheduler), parsed a particular directory, copied everything over xxx days old to an alternate location, and then deleted it out of the source directory, while appending to the log it created.  So, I know it can be done, but I am not a VBScript Expert, by any stretch o the imagination.


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Normally after a failure of Domain Controller, when promoting new DC the DC is renamed, we will discuss the options in Dcpromo to re-create the DC with the same name. Scenario: You are a small IT shop with two Domain Controllers (Domain Contr…
    Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
    This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
    This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now