// Copies the file specified in the path ASource to ADest// The file names are specified in UTF-8procedure MyCopyFile(const ASource, ADest: string);var SourceF, TargetF: File; Buffer: array[1..2048] of Char; // The amount read and written for BlockRead and BlockWrite NumRead, NumWritten: Int64;begin // Open the source file AssignFile(SourceF, UTF8ToSys(ASource)); Reset(SourceF, 1); // Note that we specify the size the file records try // Now open the destination file AssignFile(TargetF, UTF8ToSys(ADest)); Rewrite(TargetF, 1); // Note that we specify the size the file records repeat BlockRead(SourceF, Buffer, SizeOf(Buffer), NumRead); // Read ... and BlockWrite(TargetF, Buffer, NumRead, NumWritten); // copy the data until (NumRead = 0) or (NumWritten <> NumRead); // until there is nothing else to read finally CloseFile(SourceF); CloseFile(TargetF); end; ShowMessage('The file “' + OpenDialog1.FileName + '” was copied to “' + SaveDialog1.FileName + '”.');end;
procedure CopyFile(Source, Target: String);var S: TFileStream = NIL; T: TFileStream = NIL;begin S := TFileStream.Create(Source, fmOpenRead); try T := TFileStream.Create(Target, fmOpenWrite or fmCreate); T.CopyFrom(S, S.Size); FileSetDate(T.Handle, FileGetDate(S.Handle)); // Copy the date too finally if T <> NIL then T.Free; S.Free; end;end;
var f: File of Byte; b: Byte;begin Assign(f,FileName); Reset(f); Read(f,b); // reads a single byte from the file Close(f);end;
how do I read file from bottom to reach the top of the file!