Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How do I copy only changed files  (Read 20177 times)

0 Members and 1 Guest are viewing this topic.

geoffl

    Topic Starter


    Intermediate

    • Experience: Beginner
    • OS: Unknown
    How do I copy only changed files
    « on: August 01, 2016, 10:20:26 PM »
    Hi,
    I use a batch file to back up a directory on a computer on my network to my computer. There are 800 small files and it takes some time. Is there a way I could copy only files which have changed since last backup?
    Regards
    Geoffl

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: How do I copy only changed files
    « Reply #1 on: August 01, 2016, 11:55:16 PM »
    Make use of the archive attribute.
    http://www.computerhope.com/jargon/a/archivea.htm
    The backup program  can use this to show a faille has been backed up or not.
    Whenever a file is altered, MS-DOS will make the file ready for archive.
    http://www.computerhope.com/jargon/a/archival.htm





    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: How do I copy only changed files
    « Reply #2 on: August 02, 2016, 12:37:09 AM »
    xcopy also works well for copying only files changed since last backup by looking at date time stamps such as shown below


    Quote
    XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                               [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                               [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/B]
                               [/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.  Each string
                   should be in a separate line in the files.  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 the size of 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.
      /G           Allows the copying of encrypted files to destination that does
                   not support encryption.
      /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.
      /B           Copies the Symbolic Link itself versus the target of the link.
      /J           Copies using unbuffered I/O. Recommended for very large files.

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

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: How do I copy only changed files
    « Reply #3 on: August 02, 2016, 08:49:26 AM »
    When files are changed, it sets the Archive attribute.  So you can use xcopy with the /M option.

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: How do I copy only changed files
    « Reply #4 on: August 02, 2016, 09:22:10 AM »
    Quote
    When files are changed, it sets the Archive attribute.

    Very cool... all these years I didnt know that, and used the date/time stamp instead since it changes when the file is edited and newly created files carry over to the most recent backup. I had always thought that files had to have an attrib function done to them to get the archive attribute tag and then use the /M then to only copy those files, so for years I have been using /D instead of /M. Thanks squashman  :)

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: How do I copy only changed files
    « Reply #5 on: August 02, 2016, 08:07:27 PM »
    robocopy is the upgraded xcopy in Windows these days.

    It has a /mir option that creates an exact copy of the folder tree.
      - only copying changed or added files, plus removing files from the target which no longer exist in the source folder.


    It's an incredibly powerful copying tool, but don't get the folders wrong.

    There's no problem if you use a foldername that does not exist as the target folder, but if you use a different existing folder by mistake then it will be emptied rapidly as robocopy mirrors the source folder.

    There are the usual forms of copying too - it is the /MIR switch and /PURGE switch that can bite someone who isn't paying attention.

    geoffl

      Topic Starter


      Intermediate

      • Experience: Beginner
      • OS: Unknown
      Re: How do I copy only changed files
      « Reply #6 on: August 02, 2016, 10:05:34 PM »
      Thank you so much. You have saved me 5 minutes every day.
      Regards
      Geoffl

      DaveLembke



        Sage
      • Thanked: 662
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: How do I copy only changed files
      « Reply #7 on: August 03, 2016, 12:20:34 PM »
      Cool it all adds up... by the way curious which method you used?

      geoffl

        Topic Starter


        Intermediate

        • Experience: Beginner
        • OS: Unknown
        Re: How do I copy only changed files
        « Reply #8 on: August 03, 2016, 05:45:45 PM »
        Just a batch file ' copy t:\dir\*.*  c:\back\dir\*.*'
        I just got to work and changed the copy to xcopy and now I get
        Invalid drive in search path
        Invalid drive in search path
        Bad command or file
        I am running this under NTVDM Does that make a diffrernce?

        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        Re: How do I copy only changed files
        « Reply #9 on: August 04, 2016, 06:00:43 AM »
        Just a batch file ' copy t:\dir\*.*  c:\back\dir\*.*'
        I just got to work and changed the copy to xcopy and now I get
        Invalid drive in search path
        Invalid drive in search path
        Bad command or file
        I am running this under NTVDM Does that make a diffrernce?
        Please use CODE tags when posting code.  Why are you not using the  /M switch.  That was the whole point of using XCOPY.

        Now here is one more point.  Obviously you are obfuscating your code and directory names.  Doing that will a lot of times, not help us figure out what the problem is.  If you are going to obfuscate then you need to still stick to what pattern of what you are actually trying to do.

        geoffl

          Topic Starter


          Intermediate

          • Experience: Beginner
          • OS: Unknown
          Re: How do I copy only changed files
          « Reply #10 on: August 04, 2016, 05:31:33 PM »
           I was using "  copy t:\fms\*.*  c:\back\fms\*.*   "
          I changed it to   "  xcopy t:\fms\*.*  c:\back\fms\*.*  /m /y  " and it works fine under the command prompt. It does not work under NTVDM

          foxidrive



            Specialist
          • Thanked: 268
          • Experience: Experienced
          • OS: Windows 8
          Re: How do I copy only changed files
          « Reply #11 on: August 04, 2016, 09:56:08 PM »
          I changed it to   "  xcopy t:\fms\*.*  c:\back\fms\*.*  /m /y  " and it works fine under the command prompt.
          It does not work under NTVDM

          What are you referring to when you say "NTVDM"?
          What error message do you see on the screen?
          Use pause as the last line if the window disappears.

          patio

          • Moderator


          • Genius
          • Maud' Dib
          • Thanked: 1769
            • Yes
          • Experience: Beginner
          • OS: Windows 7
          Re: How do I copy only changed files
          « Reply #12 on: August 04, 2016, 10:19:53 PM »
          I despise made up acronyms...
          " Anyone who goes to a psychiatrist should have his head examined. "

          geoffl

            Topic Starter


            Intermediate

            • Experience: Beginner
            • OS: Unknown
            Re: How do I copy only changed files
            « Reply #13 on: August 04, 2016, 10:30:00 PM »
            NT virtual dos machine. Error is bad command or file.

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: How do I copy only changed files
            « Reply #14 on: August 04, 2016, 10:53:05 PM »
            NT virtual dos machine. Error is bad command or file.

            That error means you typed the command name wrong, or the command is not on the path.
            It's not Windows NT line either - "Bad command or filename" is an MSDOS error message.