So while I was messing with opening files and Arrays, I partly made a semi-delta copying program.
...which I don't have the code with me because I wasn't planning on posting yet. -_-
But I started with the tutorial piece below.
So I have it comparing files with md5 hashes of the file sections*, but after I done all that I was at a loss as to how BlockWrite works for file position.
(*I just convert the 'Block' array into a string and hash that.)
I Think if I get a hash match, I can skip the call to BlockWrite, BUT if I do that, then from what I've read, the next BlockWrite will just start writing to the file at the same position as the skipped one. (Right?)
So How do I 'move' the BlockWrite 'start' position?
Tutorial Code:
program FilesCopy2;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils
{ you can add units after this };
var
SourceName, DestName: string;
SourceF, DestF: file;
Block: array [0 .. 1023] of Byte;
NumRead: Integer;
begin
Writeln('Files copy');
Write('Input source file name: ');
Readln(SourceName);
Write('Input destination file name: ');
Readln(DestName);
if FileExists(SourceName) then
begin
AssignFile(SourceF, SourceName);
AssignFile(DestF, DestName);
FileMode:= 0;
// open for read only
Reset(SourceF, 1); // open source file
Rewrite(DestF, 1); // Create destination file
// Start copy
Writeln('Copying..');
while not Eof(SourceF) do
begin
// Read Byte from source file
BlockRead(SourceF, Block, SizeOf(Block), NumRead);
// Write this byte into new destination file
BlockWrite(DestF, Block, NumRead);
end;
CloseFile(SourceF);
CloseFile(DestF);
end
else // Source File not foundWriteln('Source File does not exist');
Write('Copy file is finished, press enter key to close..');
Readln;
end.