Hello,
I want to put some files together, but
I have problem, when I'm trying to write data into opened file from another file.
Structure of compiled file:
- Head: total count of files in file
- Sizes: names and the sizes of the files
- File Streams
so I wrote a script to write head and sizes. It worked fine, but when I tried to add a script to read file from a list and write its content into the compiled file, I detected some errors. This is the code (it's just a part, not everything):
THead = record
count:byte;
end;
TSizes = record
size:LongWord;
name:string[255];
end;
var myFile,streamFile: File;
th: THead;
ts: array of TSizes;
i:integer;
Buffer: array[0..255] of Byte;
begin
if SaveDialog1.Execute then
begin
AssignFile(myFile, SaveDialog1.FileName);
Rewrite(myFile);
SetLength(ts,Memo1.Lines.Count);
th.count := Memo1.Lines.Count;
BlockWrite(myFile,th,1);
for i:=0 to Memo1.Lines.Count-1 do
begin
ts[i].size := Get_File_Size(Memo1.Lines[i]);
ts[i].name := TrimLength(GetFileName(Memo1.Lines[i]));
BlockWrite(myFile,ts[i],1);
//the code I need to help with
AssignFile(streamFile, Memo1.Lines[i]);
Reset(streamFile);
while not Eof(streamFile) do begin
BlockRead(streamFile,Buffer,1);
BlockWrite(myFile,Buffer,1);
end;
CloseFile(streamFile);
end;
CloseFile(myFile);
end;
And after I tried this, sometimes the file to be read is not completely written to the myFile,
and sometimes the streamFile isn't read at all.
Any solutions how to write file streams at the end of the current editing file ?