Sumar ficheros (copiar uno al final de otro existente)
0000-00-00 00:00:00
program Copia; \{\$APPTYPE CONSOLE} uses SysUtils; procedure FileCopy(const FromFile, ToFile: string); var FromF, ToF: file; NumRead, NumWritten: integer; Buf: array[1..2048] of Char; begin AssignFile(FromF, FromFile); Reset(FromF, 1); { Record size = 1 } AssignFile(ToF, ToFile); { Open output file } Rewrite(ToF, 1); { Record size = 1 } repeat BlockRead(FromF, Buf, SizeOf(Buf), NumRead); BlockWrite(ToF, Buf, NumRead, NumWritten); until (NumRead = 0) or (NumWritten < NumRead); CloseFile(FromF); CloseFile(ToF); end; procedure FileCopyAdd(const FromFile, ToFile: string); var FromF, ToF: file; NumRead, NumWritten: integer; Buf: array[1..2048] of Char; begin AssignFile(FromF, FromFile); Reset(FromF, 1); { Record size = 1 } AssignFile(ToF, ToFile); { Open output file } If fileexists(Tofile) then Begin Reset(ToF, 1); seek(ToF,filesize(ToF)); end else Rewrite(ToF,1); repeat BlockRead(FromF, Buf, SizeOf(Buf), NumRead); BlockWrite(ToF, Buf, NumRead, NumWritten); until (NumRead = 0) or (NumWritten < NumRead); CloseFile(FromF); CloseFile(ToF); end; begin FileCopy('prueba1.dat','final.dat'); FileCopyAdd('prueba2.dat','final.dat'); end.
El programa es para consola, simplemente es de ejemplo, para que veais como va.