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

Author Topic: xcopy and comparing 2 diff files with same names..??  (Read 5703 times)

0 Members and 1 Guest are viewing this topic.

gumbaz

    Topic Starter


    Intermediate

    xcopy and comparing 2 diff files with same names..??
    « on: August 28, 2008, 07:41:41 AM »
    Is there any way with BATCH or VBS Ect.. to compare 2 diff files in 2 diff directories that have the same name but diff file sizes or md5 Ect..
    So if the the source file (File that will be copied to dest) is diff from the dest file, then append (1) to the dest file name, then copy the source file over to the dest directory

    Ex:
    I want xcopy to copy F:\files\data.txt  over to  C:\files\F\data.txt
    but if   C:\files\F\data.txt  already exists and is a totally diff file than  F:\files\data.txt 
    then I want a way to compare F:\files\data.txt against  C:\files\F\data.txt
    and if  F:\files\data.txt  is diff from C:\files\F\data.txt
    than I want C:\files\F\data.txt to be renamed to C:\files\F\data(1).txt
    then have xcopy copy F:\files\data.txt  over to  C:\files\F\data.txt

    Is there anyway to do this at all..??

    fireballs



      Apprentice

    • Code:Terminal
    • Thanked: 3
      Re: xcopy and comparing 2 diff files with same names..??
      « Reply #1 on: August 28, 2008, 08:16:20 AM »
      Code: [Select]
      for /f "tokens=* delims=" %%A in ('dir /b /a:-d') do (
      comp F:\files\%%A C:\files\F\%%A
      if errorlevel==1(
      set add=%%A
      set add=%add:~0,-4%
      ren c:\files\F\%%A c:\files\F\%add%(1).txt
      )
      xcopy F:\files\%%A  C:\files\F\%%A
      )

      appologies if there are any errors in that, i wrote it quickly...

      FB
      Next time google it.

      gumbaz

        Topic Starter


        Intermediate

        Re: xcopy and comparing 2 diff files with same names..??
        « Reply #2 on: August 30, 2008, 06:59:05 AM »
        thanx,
        is there anyway to make it so its not file specific though.
        so if i wanted to Mirror Xcopy the entire folder F:\Files to C:\files\F  it would copy all the Sub-Dirs + Sub-Files from F:\Files over to C:\files\F\Files and if it ran into any duplicate same named files already existing in C:\files\F\Files than it would append (1) to any of those specified duplicate named files..
        then copy over the new files..

        fireballs



          Apprentice

        • Code:Terminal
        • Thanked: 3
          Re: xcopy and comparing 2 diff files with same names..??
          « Reply #3 on: August 30, 2008, 08:10:44 AM »
          the only difference i can see in your second post is that you want to copy sub-directories and sub-files to do this use the /E argument on xcopy; substitue this line in for the one above:
          Code: [Select]
          ...
          xcopy F:\files\%%A  C:\files\F\%%A /E
          ...

          FB
          Next time google it.

          gumbaz

            Topic Starter


            Intermediate

            Re: xcopy and comparing 2 diff files with same names..??
            « Reply #4 on: August 30, 2008, 08:56:27 AM »
            Is there anyway to do the  Xcopy /e /i  first and then when it runs into existing destination file and asks you to overwrite, do the comparing then and if they are diff files append (1) to the existing dest file name,
            then xcopy over the new source file to the dest dir... 

            qinghao



              Intermediate
            • Don't think your self special
              Re: xcopy and comparing 2 diff files with same names..??
              « Reply #5 on: August 30, 2008, 09:45:25 AM »
              why don't you use the "/y" switch,
              when there is a file that already exist in the dstination folder,the command line will stop there and then prompt you a message!

              gumbaz

                Topic Starter


                Intermediate

                Re: xcopy and comparing 2 diff files with same names..??
                « Reply #6 on: August 30, 2008, 10:46:49 AM »
                but i'm trying to make an automated script to do it all without any prompting..

                qinghao



                  Intermediate
                • Don't think your self special
                  Re: xcopy and comparing 2 diff files with same names..??
                  « Reply #7 on: August 30, 2008, 11:02:41 AM »
                  Have you ever tried fireballs' CODE?

                  ALAN_BR



                    Hopeful

                    Thanked: 5
                    • Computer: Specs
                    • Experience: Experienced
                    • OS: Windows 7
                    Re: xcopy and comparing 2 diff files with same names..??
                    « Reply #8 on: August 30, 2008, 01:49:09 PM »
                    Start again !!!

                    I suggest you download WinMerge from SourceForge.

                    You aim at two targets - the two points on each drive to be compared.

                    It compares every file in each designated directory, and all their sub-directories.

                    Comparison is quick - e.g. 1 minute for 40,000 files on my Drive C:\ w.r.t. Drive L:\ using File size comparison - similar time using file date option, or a coffee break using a detailed examination of every byte in every file (that gives it 7 GByte to read !!!).

                    The results appear with one file name per row and :-
                    If it matches between both targets,
                    If it is different between both targets, or
                    Which target it is unique to.

                    Normal use is to click on any row, and a file comparison shows you all the differences between them.

                    You do not have to use the built in file comparator.

                    You can simply copy what it has found different to any other location for any sort of independent processing by your preferred tools.

                    e.g. you can rapidly select all desired files/subdirectories of one target, and either copy them or move them to the other target, or even to a totally different choice on another drive, where what you desire can be unique, different, or identical - you can even mix and match.

                    Regards
                    Alan

                    gumbaz

                      Topic Starter


                      Intermediate

                      Re: xcopy and comparing 2 diff files with same names..??
                      « Reply #9 on: August 30, 2008, 07:00:25 PM »
                      Have you ever tried fireballs' CODE?

                      yes, but its only comparing files in the F:\files\ Dir only, but not in any of F:\files\ sub Dir's or Files..
                      then it copies them one by one all into the same DIR C:\files\F\ without mirroring the Complete Folder-File Structure of F:\

                      What I want to do is something like this

                      for /f "delims==" %%S in ('DIR F:\ /A /B /S') do .....
                      for /f "delims==" %%D in ('DIR C:\Files\F /A /B /S') do .....

                      %%S = Source Files
                      %%D = Dest Files

                      Xcopy F:\  C:\Files\F  /E /I
                      If Ask for overwrite comp %%S to %%D
                      If if errorlevel==1 ren %%D  %%D(1)
                      then copy over the new source files

                      ghostdog74



                        Specialist

                        Thanked: 27
                        Re: xcopy and comparing 2 diff files with same names..??
                        « Reply #10 on: August 30, 2008, 08:08:21 PM »
                        the fc command (if you have it) does what you want.

                        gumbaz

                          Topic Starter


                          Intermediate

                          Re: xcopy and comparing 2 diff files with same names..??
                          « Reply #11 on: August 30, 2008, 08:20:42 PM »
                          OK THNX,
                          but how to incorporate it with either:
                          Xcopy F:\  C:\Files\F  /E /I
                          or
                          robocopy F:\ C:\Files\F /MIR