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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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?
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.