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 20178 times)

0 Members and 2 Guests 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.

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: How do I copy only changed files
            « Reply #15 on: August 04, 2016, 10:59:38 PM »
            I despise made up acronyms...

            Me too!  HGSF!  ;)

            geoffl

              Topic Starter


              Intermediate

              • Experience: Beginner
              • OS: Unknown
              Re: How do I copy only changed files
              « Reply #16 on: August 04, 2016, 11:18:53 PM »
              I am  guessing that copy works undex DOS but not Xcopy.

              foxidrive



                Specialist
              • Thanked: 268
              • Experience: Experienced
              • OS: Windows 8
              Re: How do I copy only changed files
              « Reply #17 on: August 04, 2016, 11:51:29 PM »
              I am  guessing that copy works undex DOS but not Xcopy.

              We are all guessing what you are doing what you are doing it with.

              geoffl

                Topic Starter


                Intermediate

                • Experience: Beginner
                • OS: Unknown
                Re: How do I copy only changed files
                « Reply #18 on: August 05, 2016, 12:29:39 AM »
                I run old DOS software under windows using NT virtual dos machine. The batch file is run by my program which I guess means it runs under DOS. I have been using the copy command and it copies every file in the directory. When I changed copy to Xxopy I get the message - bad command of file. I am wondering Why xcopy works from the command prompt but not under virtual DOS

                foxidrive



                  Specialist
                • Thanked: 268
                • Experience: Experienced
                • OS: Windows 8
                Re: How do I copy only changed files
                « Reply #19 on: August 05, 2016, 02:52:28 AM »
                I run old DOS software under windows using NT virtual dos machine. The batch file is run by my program which I guess means it runs under DOS. I have been using the copy command and it copies every file in the directory. When I changed copy to Xxopy I get the message - bad command of file. I am wondering Why xcopy works from the command prompt but not under virtual DOS

                Virtual Dos means nothing to people reading here.  We don't know what environment you are running under.
                We don't know what is in your batch file.  You've been told why that error message occurs.

                You don't understand your problem and you don't understand how poor your level of detail and information is.


                DaveLembke



                  Sage
                • Thanked: 662
                • Certifications: List
                • Computer: Specs
                • Experience: Expert
                • OS: Windows 10
                Re: How do I copy only changed files
                « Reply #20 on: August 05, 2016, 06:28:48 AM »
                When you run VER what version does it show, this way we can determine the exact OS version your running?

                such as I run VER and it shows: Microsoft Windows [Version 6.1.7601]

                If you run XCOPY/? does it show help information showing that XCOPY command exists?

                From the VER output we can determine what your running for OS environment: https://en.wikipedia.org/wiki/Ver_(command)

                Spoiler



                  Specialist

                  Thanked: 50
                • Experience: Beginner
                • OS: Windows XP
                Re: How do I copy only changed files
                « Reply #21 on: August 05, 2016, 09:56:07 AM »
                You can try Rich Copy. I use it all the time. Works great....

                https://technet.microsoft.com/en-us/magazine/2009.04.utilityspotlight.aspx?pr=blog

                It is a GUI version of robocopy written by a MS engineer.

                Whenever I watch TV and I see those poor starving kids all over the world, I can't help but cry. I mean I would love to be skinny like that, but not with all those flies and death and stuff." - Mariah Carey, Pop Singer

                BC_Programmer


                  Mastermind
                • Typing is no substitute for thinking.
                • Thanked: 1140
                  • Yes
                  • Yes
                  • BC-Programming.com
                • Certifications: List
                • Computer: Specs
                • Experience: Beginner
                • OS: Windows 11
                Re: How do I copy only changed files
                « Reply #22 on: August 05, 2016, 01:03:53 PM »
                Quote
                I am running this under NTVDM Does that make a diffrernce?
                Yep, that changes things, Running the batch via command.com via the 16-bit DOS emulation provided via NTVDM means there will be no NT Command extensions available. It also means that all paths must be 8.3 paths, and there are a number of other limitations.

                If you enter the command:
                Code: [Select]
                echo %path%what is output? From the sounds of it there may be values listed that are an invalid drive under NTVDM. This message is output when command.com starts up. It looks like two entries were considered invalid drive specs. It's also possibly why you get "Bad Command or File Name" as it cannot find xcopy as a result.

                One possible workaround is to "escape" NTVDM. For example instead of having the MS-DOS program in question run your batch file- which will go into command.com- you may be able to configure it to run your batch file through cmd (cmd /c batch.bat) if you can change the command. If not, you can have the batch file it runs instead launch your main batch file via cmd. That should hopefully prevent issues as the batch will be running under the same cmd.exe environment you've already confirmed it to function correctly with.

                For others- I am fairly certain their "batch file" consists of one xcopy command. It is running under the command.com interpreter of MS-DOS which is being launched, as described by the OP, by another MS-DOS program; This all takes place under the 16-bit emulation of NTVDM for MS-DOS applications, present in all 32-bit Windows versions. The MS-DOS command interpreter considers multiple entries in the PATH variable invalid, which is why those messages appear. when it then runs the batch itself, it can't find xcopy, possible because of those path errors - and thus emits "Bad Command or Filename".

                I was trying to dereference Null Pointers before it was cool.

                foxidrive



                  Specialist
                • Thanked: 268
                • Experience: Experienced
                • OS: Windows 8
                Re: How do I copy only changed files
                « Reply #23 on: August 05, 2016, 09:56:51 PM »
                For others- I am fairly certain their "batch file" consists of one xcopy command. It is running under the command.com interpreter of MS-DOS which is being launched, as described by the OP, by another MS-DOS program;

                 when it then runs the batch itself, it can't find xcopy, possible because of those path errors - and thus emits "Bad Command or Filename".

                I shouldn't be quite so grumpy with the guy but the error message he posted isn't from an NT series Windows command prompt.

                command.com in modern Windows is a stub that calls CMD.exe and is only there for backward compatibility to fool older programs into thinking they are running under command.com

                If you open a prompt by typing command.com and then type a bogus command you'll get the modern error message and not "Bad command or filename".



                It seems to me that the fellow is using Dosbox or Virtualbox or some other emulator and in any case is not describing what he's doing at all.  His question about an error is like going to your dentist and saying "I have a sore tooth, guess which one it is?"

                When I changed copy to Xxopy I get the message - bad command of file.

                If you typed Xxopy in your batch script then there's your problem.

                BC_Programmer


                  Mastermind
                • Typing is no substitute for thinking.
                • Thanked: 1140
                  • Yes
                  • Yes
                  • BC-Programming.com
                • Certifications: List
                • Computer: Specs
                • Experience: Beginner
                • OS: Windows 11
                Re: How do I copy only changed files
                « Reply #24 on: August 05, 2016, 10:11:47 PM »
                True enough foxidrive. I can confirm that I was incorrect, even in the specific instance where Windows XP (as you noted, no details- including OS) is used and a MS-DOS program is run and then a DOS Shell opened from the DOS program, there is no "Bad command or filename" message (and certainly not "Bad command or file" in either case.)

                One possibility could be if it is a localized version and they are translating? It might use a message like that- but again, details that ought to have been mentioned.
                I was trying to dereference Null Pointers before it was cool.

                geoffl

                  Topic Starter


                  Intermediate

                  • Experience: Beginner
                  • OS: Unknown
                  Re: How do I copy only changed files
                  « Reply #25 on: August 06, 2016, 04:50:05 PM »
                  Thank you for your help and the considerable time you have spent. You must realize that the reason people come here is because they don't have the knowledge that you people have therefore some of the questions and answers can be a little confusing. I am a little concerned with Patio. My best guess is that he is an agro 12 year old going through puberty and has not learnt any social graces yet. Maybe some of you more intelligent guys could take him under your wing and teach him that abusive comments (most of what I see from him) drives people away from this site which, to me, has been a wonderful source of information. Thank you again.
                  Geoffl

                  patio

                  • Moderator


                  • Genius
                  • Maud' Dib
                  • Thanked: 1769
                    • Yes
                  • Experience: Beginner
                  • OS: Windows 7
                  Re: How do I copy only changed files
                  « Reply #26 on: August 06, 2016, 05:22:20 PM »
                  Well my sincere apologies for pointing out a non-existing acronym that took 14 posts to be explained...

                  Hope you feel better.
                  " 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 #27 on: August 06, 2016, 05:27:51 PM »
                    I think you might be a few bricks short of a chimney!

                    BC_Programmer


                      Mastermind
                    • Typing is no substitute for thinking.
                    • Thanked: 1140
                      • Yes
                      • Yes
                      • BC-Programming.com
                    • Certifications: List
                    • Computer: Specs
                    • Experience: Beginner
                    • OS: Windows 11
                    Re: How do I copy only changed files
                    « Reply #28 on: August 06, 2016, 05:56:23 PM »
                    If you put half the effort into providing real details that you did into composing a misdirected personal attack, this thread could actually make some forward progress.
                    I was trying to dereference Null Pointers before it was cool.

                    foxidrive



                      Specialist
                    • Thanked: 268
                    • Experience: Experienced
                    • OS: Windows 8
                    Re: How do I copy only changed files
                    « Reply #29 on: August 07, 2016, 05:30:35 AM »
                    has not learnt any social graces yet.

                    geoffl, you still fail to provide details about the subject at hand and yet you write things like that above.
                    Look in the mirror, my friend.