Comparing Files

BlitzMax Forums/BlitzMax Beginners Area/Comparing Files

PaulJG(Posted 2005) [#1]
I've written this little proggie thats suppose to compair the contents of 2 files - source & master - and write out any changes into a third file - combi.

But its failing around the LEN commands, any kind person give me a push in the right direction please.

(As ya can see for yourself, if the master file is different to the source then it takes priority)

Local master_buffer:String
Local source_buffer:String

Local masterbufflen:Int
Local sourcebufflen:Int

master=ReadStream("c:\\master.txt")
If Not master RuntimeError "Failed to open MASTER file"

source=ReadStream("c:\\source.txt")
If Not source RuntimeError "Failed to open SOURCE file"

combi=CreateFile("c:\\combi.txt")
If Not combi RuntimeError "Error creating file"
combi=OpenStream("c:\\combi.txt")

While Not Eof(master)
	
	master_buffer=ReadLine(master)
	source_buffer=ReadLine(source)
	
	sourcebufflen=Len(source_buffer)
	masterbufflen=Len(master_buffer)			
	
	Print sourcebufflen
	Print masterbufflen
	
	If sourcebufflen<masterbufflen Then
		Print master_buffer
		WriteLine(combi,master_buffer)
	EndIf
	
	If sourcebufflen>masterbufflen Then
		Print source_buffer
		WriteLine(combi,source_buffer)
	EndIf
	
Wend


CloseStream master
CloseStream source
CloseStream combi



tonyg(Posted 2005) [#2]
It alls seems to work OK for me with very simple 2 line text files...
This is the first text 
file that I'll be checking

This is the second text
file that I'll be checking

Results are...
23
22
this is the second text
26
26

with combi.txt containing...
this is the second text

Bmx 1.10


PaulJG(Posted 2005) [#3]
Thanks !, didnt think it was working at all.

Seems to depend on the size and contents of which file its copying from.. loadsa bugs yet. :(