Help :: How to compare two files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Kunal
Posts: 6
Joined: 01 Dec 2011 04:37

Help :: How to compare two files

#1 Post by Kunal » 02 Dec 2011 05:18

dear All,

I'm new to this batch world, so any help much appreciated.

I have two files I need to compare those files and if there is differences may be in size, time modified then it will copy to other directory?

I want to implment this in batch script so, any help will be really appreciated ?
and if any other script can achive this one , are also appreciated, but I need how add that script so that I can accomodate it in batch script.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help :: How to compare two files

#2 Post by Ed Dyreen » 02 Dec 2011 05:39

'
Sorry for my short reply, but this should get you started already:

Code: Select all

fc /?
comp /?

Kunal
Posts: 6
Joined: 01 Dec 2011 04:37

Re: Help :: How to compare two files

#3 Post by Kunal » 02 Dec 2011 06:40

no worries, that's a great start offcourse , thanks . I alreday tried that one, but anyway can you help me to refine my query further a bit

my comp gives a whole lots of lines
echo n | comp a.txt b.txt > out.txt
like comparing a.txt with b.txt
Files compare OK

n

now my question is how to find there is difference in files from out.txt
and if so then I need to move b.txt to some other loactaion?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help :: How to compare two files

#4 Post by Ed Dyreen » 02 Dec 2011 15:49

'
I did some tests, here are the results:
Compare.CMD

Code: Select all

@echo off
::
::fc /?
::
fc /l /n /w "compare.CMD" "compare.CMD" >out.TXT
fc /l /n /w "compare.CMD" "compare.CMD" &&echo.NOT different ||echo.different
fc /l /n /w "compare.CMD" "out.TXT" &&echo.NOT different ||echo.different

pause
exit

Code: Select all

Bezig met het vergelijken van bestanden compare.CMD en COMPARE.CMD
FC: geen verschillen gevonden

NOT different
Bezig met het vergelijken van bestanden compare.CMD en OUT.TXT
***** compare.CMD
    1:  @echo off
    2:  ::
    3:  ::fc /?
    4:  ::
    5:  fc /l /n /w "compare.CMD" "compare.CMD" >out.TXT
    8:  fc /l /n /w "compare.CMD" "compare.CMD" &&echo.NOT different ||echo.diff
erent
   10:  fc /l /n /w "compare.CMD" "out.TXT" &&echo.NOT different ||echo.differen
t
   12:  pause
   13:  exit
***** OUT.TXT
    1:  Bezig met het vergelijken van bestanden compare.CMD en COMPARE.CMD
    2:  FC: geen verschillen gevonden
*****

different
Druk op een toets om door te gaan. . .
I've read on the forums, sometimes the binary switch seems required for a successful compare.


Hope it helps,
Ed

Post Reply