Concatenating files

Howard Bornstein bornstein at
Thu May 30 14:38:01 EDT 2002

I'm building a small app to concatenate separate files. Specifically, I'm 
trying to join multi-part files posted to Usenet. These files are 
typically binary (movies, MP3s, etc.).

First I used the Open, Read, and Write file commands:

open file "FinalOutput"
  -- fld "Inputfiles" holds the list of file names making up the "parts"
  put the number of lines in fld "inputfiles" into linecnt

  repeat with i = 1 to linecnt
    put line i of fld "inputfiles" into thefiletoread
    open file thefiletoread for binary read
    read from file thefiletoread until EOF
    write it to file "FinalOutput" at EOF
    close file thefiletoread
  end repeat
close file "FinalOutput"

This works in the sense that it concatenates the file, but it modifies 
the binary data somehow, so the the joined file no longer plays.

In fact, I tried this on a single file small jpeg image--just read the 
file in and write it out to a different name. The file went from 20,886 
bytes down to 12,736 bytes. The jpeg sort of displays, but it's got lots 
of garbage in it.

So then I went with the get URL commands:

  repeat for each line thisline in fld "Inputfiles"
    get URL ("binfile:"& thisline)
    put it after URL "binfile:FinalOutput"
  end repeat

This ALSO scrunches the file down to 12,736 bytes (??!) but the file 
comes out fine. I've used this to concatenate groups of files and it 
works, but it is REALLY slow--orders of magnitude slower than the 
OPEN/READ/WRITE commands (even with the "repeat for each" stucture.)

Why is the data getting trashed with the OPEN/READ/WRITE commands and/or 
is there some way to speed up the get/put URL commands?


Howard Bornstein
D E S I G N  E Q

More information about the use-livecode mailing list