• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 521
  • Last Modified:

Create a Batch File to Copy then Delete

I wanted to create a batch file where I would look at a particular folder see what files are older than 7 days and to move not copy those files to a different location.  If a move is not possible then a copy and delete batch file would work as well.  The 7 days would be based off the system clock so we would need to worry about leap years or what not.  Any assistance on this would be appreciated.
  • 4
  • 3
1 Solution
You only need robocopy to do that (see download below, Vista or later has it by default); one of the best copy tools ever.
Some remarks:
- robocopy will *by* *default* only copy files that aren't in the target already.
- You might want to set /r (retry) and /w (wait) to something more useful in a LAN, like /r:2 /w:1.
- use /copyall to copy NTFS permissions as well.
- Check robocopy.doc in the ResKit installation folder (to run it, you actually only need robocopy.exe), it's a very useful documentation.
- You can safely use /nfl (no file list) and /ndl (no directory list) to reduce the log file size; errors will still be logged.
- Use /np if you're logging to a text file, otherwise the log will be filled with control characters.

In your case, you need the /mov (or /move if you want to move the folders as well), as well as /minage:7
robocopy "S:\ource\folder" "T:\arget\folder" *.* /mov /minage:7 /r:2 /w:1

Note especially the /L argument; this will simulate a run and tell you which files would be moved, without actually doing anything.

Windows Server 2003 Resource Kit Tools

GUI wrappers are available, too:
RoboCopy GUI

Utility Spotlight Robocopy GUI
mekkattiljjAuthor Commented:
So the following is my command:
echo move stated at %date% %time%
robocopy "D:\JoJo Stuff\Scans" D:\test *.* /mov /minage:7 /r:2 /w:1
This is the result:
c:\>echo move stated at Mon 04/12/2010 15:51:34.69
move stated at Mon 04/12/2010 15:51:34.69
c:\>robocopy "D:\JoJo Stuff\Scans" D:\test *.* /mov /minage:7 /r:2 /w:1
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
  Started : Mon Apr 12 15:51:34 2010
   Source : D:\JoJo Stuff\Scans\
     Dest : D:\test\
    Files : *.*
  Options : *.* /COPY:DAT /MOV /MINAGE:7 /R:2 /W:1
                           0    D:\JoJo Stuff\Scans\
                Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :         1         0         1         0         0         0
    Files :         0         0         0         0         0         0
    Bytes :         0         0         0         0         0         0
    Times :   0:00:00   0:00:00                       0:00:00   0:00:00
    Ended : Mon Apr 12 15:51:34 2010

How can I find out why it would be skipping that directory?
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

mekkattiljjAuthor Commented:
I should probably state that all data within the "scans" folder are folder themselves.  Within the folders are scans that may or maynot be older than 7 days.  So how would I get that specific?
Because one folder (the target folder itself) already existed in the target folder. Skipped files in robocopy are harmless, it just means that there was no need to copy/move a file or folder.
Only failed or mismatched files are indicators of problems.
mekkattiljjAuthor Commented:
Nevermind, I got it I had to add the switch /s but I do get a 1 skipped is there a way to get a reason why it was skipped?
As I said: "skipped" means the file/folder already existed in the same version/with the same name in the target folder.
"Skipped"does NOT mean "Failed".
mekkattiljjAuthor Commented:
Sorry, I put most of that in before you replied...either way thanks a whole bunch.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now