WHILE File End(1) = 0
READ FILE 1, thisb
WRITE FILE 2,thisb
ENDWHILE
I'm not surprised that such a loop takes a long time to execute. When fetching or writing data to a drive, a better approach is to buffer in block in memory rather than it byte by byte, since drives have such large read/write latency.
So you'd create a small mem block buffer then step through the source file in chunks of the buffer size. SO reading a chunk, then writing a chunk.
(DBpro styled Example written in PB)
SrcFile$="e:\SomeFile.data"
DestFile$=replace$(SrcFile$,".data","_copy.data")
if SrcFile$<>DEstFile$
Size_Of_File =FileSize(SrcFile$)
HunkSize =$10000
SrcFileHandle =ReadNewFile(SrcFile$)
DestFileHandle =WriteNewFile(DestFile$)
TempBank = NewBank(HunkSize)
Hunks=Size_Of_File/HUnkSize
; Copy the file in
for Hunklp=1 to HUnks
SpoolData(SrcFileHandle,DestFileHandle,TempBank, HunkSize)
next
; copy any remaining bytes
SpoolData(SrcFileHandle,DestFileHandle,TempBank, Size_Of_File-(Hunks*HunkSize))
; Kill temp buffer
DeleteBank TempBank
; close files
Closefile SrcFIleHandle
CloseFile DestFileHandle
endif
print "DONE"
print srcfile$
print destfile$
print FileSize(SrcFIle$)
print FIleSize(DestFIle$)
sync
waitkey
Function SpoolData(SrcFileHandle,DestFileHandle,Bank, Size)
; Read a block of data into the temp buffer
For lp=0 to Size-1
PokeBankByte Bank, lp, ReadByte(SrcFileHandle)
next
; SPit this block of data back out to the output file
For lp=0 to Size-1
WriteByte DestFileHandle, PeekBankByte(Bank,lp)
next
endFunction
I still wouldn't recommended reading
Byte by Byte though, use the biggest data type that dbpro allows you to read/write when accessing the data. Preferable read/writing the entire block in one hit. There's bound to be plug in that offers this.. (Read/Write Memory)
Another approach would be to do the entire merge in memory. First calc the total size of the output file and allocate an appropriately sized mem block. Then read the files into the buffer. When done, save the entire mem block..