David Overton's Blog and Discussion Site
This site is my way to share my views and general business and IT information with you about Microsoft, IT solutions for ISVs, technologists and businesses, large and small. I specialise in Windows Intune and SBS 2008.
This blog is purely the personal opinions of David Overton. If you can't find the information you were looking for e-mail me at admin@davidoverton.com.

To find out more about my Windows Intune BOOK - Microsoft Windows Intune 2.0: Quickstart Administration click here

To find out more about my SBS 2008 BOOK - Small Business Server 2008, Installation, Migration and Configuration click here

How to copy or archive files by year using the command line and robocopy
David Overton's Blog

Buy my books

Windows Intune:Quickstart Administration


This is the RAW book (Read as Written).
Click here for more information
Buy or pre-order today

SBS 2008 - Installation, Migration and Configuration

Small Business Server 2008 – Installation, Migration, and Configuration

Buy today in book or e-book form

Request a Review Copy

Twitter

Syndication

I got this question via e-mail and decided I would post the answer here in a blog.

I want transfer all files created in Office Word 2003 by year (annual batchs - ex: 2005, 2006, etc.) to external HD. How can to do this?

I will appreciate your answer.

Edgar

To do this via the command line you can use Robocopy which is present in Windows Vista and Windows 7.  If you have Windows XP download the Server 2003 Resource Toolkit and install it.  Robocopy will be part of the install and found in the install directory.

The actual command would look like this and would need to be entered into a command prompt:

for /L %x in (2009,-1,2000) do robocopy source destination\%x *.doc? /minage:%x0101 /maxage:%x1231 /s

To break it down a bit..

  • for /L %x in (2009,-1,2000) do

This creates a counter from 2009 up in steps of -1 (or down in steps of 1) until 2000 is reached.  Each time the counter changes it is set into %x, so %x will become 2009, 2008 and so on.  It then executes the command after to "do".

  • robocopy source destination\%x *.doc? /minage:%x0101 /maxage:%x1231 /s

The robocopy command is very flexible.  Details of it can be found on the wiki page here

  1. The first two parameters are the sounce and destination locations.  so it might be c:\users\david\documents and F:\document_backup.  Note the \%x on the end.  This means it will put the files inside a folder on the destination location that matches the year you are archiving.
  2. *.doc? is a limiter to the files to be copied - if you want all files, simply remove it.  This will copy all Office 2003 and 2007 document files - if you only want Office 2003, use *.doc and don't include the question mark.
  3. The minage and maxage state how old the file is.  It can either be in days or a date in the form of yyyymmdd.  So with the %x set to 2009, the command will have /minage:20090101 /maxage:20091231 which equates to everything in 2009 and so on.
  4. The /s copies all subdirectories too
  5. You can optionally put the /MOV (to move the files) or /MOVE (to move all files and empty directories) command on the end.

 

I hope that helps

 

David


Posted Wed, May 6 2009 11:26 AM by David Overton

Add a Comment

(optional)  
(optional)
(required)  
Remember Me?

(c)David Overton 2006-13