Page 1 of 1

What is a good way to join files together?

Posted: Fri Dec 10, 2004 6:25 pm
by rich
Hi all,

I have written a program which successfully downloads a file from a web site. The file is downloaded in 1MB chunks. The end result being that I have approx. 200 "chunks" in my temporary folder and I need a bullet-proof way to stitch them back together again into a single file.

Does anyone have any suggestions as how best to achieve this? I thought I could use OpenFile to create my new file and then read in each chunk one after the other and write the data out with WriteData, but I am worried that the file buffer will never actually save until I call CloseFile (or the app ends?) and i'll fill up my memory with 200MB+ worth of file buffer data.

Any ideas very welcome.

Thanks,

Rich

Posted: Fri Dec 10, 2004 7:16 pm
by blueznl
file system is not stored in memory when using the purebasic commands (except for windows caching)

Posted: Sat Dec 11, 2004 6:29 pm
by rich
For anyone else who reads this - I found a rather elegant and fast solution to this other than the byte by byte reading process. I basically create a batch file that just has a single copy command in it, such as:

copy /y part1.bin /b + part2.bin /b + part3.bin /b DestFile.zip /b

(The /y surpresses output, the /b means join as binary)

I then just run the batch file with RunProgram, set to halt until it's finished and show no output.

Works a treat! I managed to join together an entire CD ISO image this way (720 x 1MB chunks) with no errors. I was impressed that the copy command could handle having 720 "parameters" passed to it :)

It may not be cross-platform, but that's not an issue in this case. And it was certainly quicker than a byte for byte copy.

Rich