'=========================================================================== ' Subject: COMPARE 2 FILES FOR DIFFERENCES Date: 06-29-98 (00:08) ' Author: Matt Gulden Code: QB, QBasic, PDS ' Origin: www.thrillhaus.com/basic.html Packet: MISC.ABC '=========================================================================== ' COMPARE.BAS ' by Matt Gulden ' http://www.thrillhaus.com/ ' A *fast* file compare routine. You need quickbasic to run this... ' It's most useful when it's compiled... Do whatever the heck you want ' with this code. ON ERROR GOTO ErrorHandling IF INSTR(COMMAND$, " ") THEN FILE1$ = LEFT$(COMMAND$, INSTR(COMMAND$, " ") - 1) FILE2$ = RIGHT$(COMMAND$, LEN(COMMAND$) - INSTR(COMMAND$, " ")) ELSE PRINT "Usage: COMPARE file1 file2": END END IF ' Set the variable FILE$ to the file that we're opening so error handling ' can tell us, in the event of a file i/o error, which file doesn't exist FILE$ = FILE1$ OPEN FILE1$ FOR INPUT AS 1 ' Same as last comment FILE$ = FILE2$ OPEN FILE2$ FOR INPUT AS 2 WHILE NOT EOF(1) AND NOT EOF(2) ' Get the first byte from each file BYTE1$ = INPUT$(1, 1) BYTE2$ = INPUT$(1, 2) ' Compare them IF NOT BYTE1$ = BYTE2$ THEN IF LOC(1) = 1 THEN PRINT "Files differ at first byte" ELSE PRINT "Files differ at"; LOC(1); "bytes" END IF END END IF WEND PRINT LCASE$(FILE1$); " and "; LCASE$(FILE2$); " are exactly the same..." CLOSE END ErrorHandling: IF ERR = 53 THEN PRINT "File Not Found: "; FILE$ ELSE PRINT "Error:"; ERR END IF END