Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need copy  changed and new files only from one directory to another.

Posted on 2001-06-08
4
Medium Priority
?
753 Views
Last Modified: 2013-12-28
Need copy files from one directory to another.  These directories/subdirectories are supposed to be the same.  However, one of the directories had many changes applied to it during the last week.  Consequently, I would like to copy only files which have changed or have been added to the directory/subdirectories only during the last week.  Any ideas?
0
Comment
Question by:losgadas
4 Comments
 
LVL 2

Expert Comment

by:Macros
ID: 6168271
You can use Robocopy from the Resource Kit.

Syntax:

Robocopy <source> <destination> /MAXAGE:n

MAXAGE excludes files older that "n" days or date. If n is less than 1900 it is the number of days. Otherwise it is a date in the format YYYYMMDD. In your case you could just use 7 for all files added or modified in the last 7 days.

Read Robocopy.doc in the Resource Kit directory for all the switches - it's a very useful tool.

If you don't have the Resource Kit you can use
XCOPY source destination /D:m-d-y
which will copy file changed on or after the specified date. The limitation of this is that you will want to change the date on it every time you run it if you are using it regularily.
0
 
LVL 10

Expert Comment

by:tonnybrandt
ID: 6168728
Or simply use the xcopy command with the /m parameter. This checks for the archive attribute and if it is set it copies it and clears the attribute. Every time a file is written, whether it is a new or changed file, the archive attribute is set, so this is IMHO the best and most thorough method.

Here is the complete listing of parameters to the xcopy command:

E:\>xcopy /?
Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                           [/EXCLUDE:file1[+file2][+file3]...]

  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A           Copies only files with the archive attribute set,
               doesn't change the attribute.
  /M           Copies only files with the archive attribute set,
               turns off the archive attribute.
  /D:m-d-y     Copies files changed on or after the specified date.
               If no date is given, copies only those files whose
               source time is newer than the destination time.
  /EXCLUDE:file1[+file2][+file3]...
               Specifies a list of files containing strings.  When any of the
               strings match any part of the absolute path of the file to be
               copied, that file will be excluded from being copied.  For
               example, specifying a string like \obj\ or .obj will exclude
               all files underneath the directory obj or all files with the
               .obj extension respectively.
  /P           Prompts you before creating each destination file.
  /S           Copies directories and subdirectories except empty ones.
  /E           Copies directories and subdirectories, including empty ones.
               Same as /S /E. May be used to modify /T.
  /V           Verifies each new file.
  /W           Prompts you to press a key before copying.
  /C           Continues copying even if errors occur.
  /I           If destination does not exist and copying more than one file,
               assumes that destination must be a directory.
  /Q           Does not display file names while copying.
  /F           Displays full source and destination file names while copying.
  /L           Displays files that would be copied.
  /H           Copies hidden and system files also.
  /R           Overwrites read-only files.
  /T           Creates directory structure, but does not copy files. Does not
               include empty directories or subdirectories. /T /E includes
               empty directories and subdirectories.
  /U           Copies only files that already exist in destination.
  /K           Copies attributes. Normal Xcopy will reset read-only attributes.
  /N           Copies using the generated short names.
  /O           Copies file ownership and ACL information.
  /X           Copies file audit settings (implies /O).
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
  /Z           Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.
0
 
LVL 11

Accepted Solution

by:
LambertHeenan earned 120 total points
ID: 6168736
good old Xcopy (available since MS-DOS 3.0) can hadle that.

xcopy \SourceDir\*.* \DestDir /S /A /D:m-d-y

/S -- process sub-dirs too
/A -- process files with the archive bit st (as all changed files will have)
/D -- process files dated on or after the supplied date

XCOPY /? for full syntax details

If you do this every week then you only need the /A switch for xcopy to locate any files changed since the lst time.
0
 
LVL 27

Expert Comment

by:Asta Cu
ID: 6173673
losqadas,

    You have asked a new question, again experts have stepped in to help you, but no closure or response.  You have a number of open question awaiting your return and update and/or finalization.  Please do keep your open items active so that you can get what you seek and finalize your open items, awarding those who have helped you.

Thanks,

Asta
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
IF you are either unfamiliar with rootkits, or want to know more about them, read on ....
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

916 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