stephen_graham
asked on
Cutting files in packs
Hi,
I was wondering if anyone knew how to seperate files into segments for backup or something.
I mean, if I had a 3 MB file and wanted it to be split up into files of 1 MB each. If anyone has anycode to be able to do so (splitting up code and putting back together code) I would be extremely greatful.
Thanks,
SG
I was wondering if anyone knew how to seperate files into segments for backup or something.
I mean, if I had a 3 MB file and wanted it to be split up into files of 1 MB each. If anyone has anycode to be able to do so (splitting up code and putting back together code) I would be extremely greatful.
Thanks,
SG
Listening
ASKER
Sorry,
Can't get your code to work Umulig. I have corrected most syntax but there are still problems. Could you rewrite the BlockWrite proc. for me if you have time (I have taken the buf var to be a string).
Thanks
SG
Can't get your code to work Umulig. I have corrected most syntax but there are still problems. Could you rewrite the BlockWrite proc. for me if you have time (I have taken the buf var to be a string).
Thanks
SG
buf should be array[0..size-1] of char.
pass buf[0] to the function BlockRead and BlockWrite.
Good luck
Kelly
pass buf[0] to the function BlockRead and BlockWrite.
Good luck
Kelly
hi friends,
delphi provides a good streaming feature, therefore
a solution with streams:
procedure TForm1.Button1Click(Sender : TObject);
var
i, WantedFragSize, RealToWrite : Integer;
InStream, OutStream : TFileStream;
S : String;
begin
if Opendialog1.Execute then
begin
SaveDialog1.Title := 'Select Dir and input FilePrefix without Suffix';
If SaveDialog1.Execute then
begin
WantedFragSize := StrtoInt(Edit1.Text);
i := 0;
InStream := TFileStream.Create(OpenDia log1.FileN ame,fmOpen Read);
try
while (InStream.Position < InStream.Size) do
Begin
s := IntToStr(I);
while Length(s) < 3 do s := '0'+s;
s := '.'+s;
If InStream.Size - InStream.Position < WantedFragSize then
RealToWrite := InStream.Size - InStream.Position
else
RealToWrite := WantedFragSize;
OutStream := TFileStream.Create(SaveDia log1.FileN ame+s,fmCr eate);
try
OutStream.CopyFrom(InStrea m,RealToWr ite);
Inc(i);
finally
OutStream.Free;
end;
end;
Finally
InStream.Free;
end;
end;
end;
end;
meikl
delphi provides a good streaming feature, therefore
a solution with streams:
procedure TForm1.Button1Click(Sender
var
i, WantedFragSize, RealToWrite : Integer;
InStream, OutStream : TFileStream;
S : String;
begin
if Opendialog1.Execute then
begin
SaveDialog1.Title := 'Select Dir and input FilePrefix without Suffix';
If SaveDialog1.Execute then
begin
WantedFragSize := StrtoInt(Edit1.Text);
i := 0;
InStream := TFileStream.Create(OpenDia
try
while (InStream.Position < InStream.Size) do
Begin
s := IntToStr(I);
while Length(s) < 3 do s := '0'+s;
s := '.'+s;
If InStream.Size - InStream.Position < WantedFragSize then
RealToWrite := InStream.Size - InStream.Position
else
RealToWrite := WantedFragSize;
OutStream := TFileStream.Create(SaveDia
try
OutStream.CopyFrom(InStrea
Inc(i);
finally
OutStream.Free;
end;
end;
Finally
InStream.Free;
end;
end;
end;
end;
meikl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks alot everyone for helping but I found meikl's answer the best,
Thanks alot and here are your well awarded points!
SG
Thanks alot and here are your well awarded points!
SG
outf: file;
size: longint;
outsize: longint;
amt: word;
amtRead: word;
assignfile (inf, 'input file');
reset (inf, 1);
size := fileSize (inf);
repeat
showMessage (enter floppy in "A") { or "B" or allow them to specify }
assignFile (outf, 'A:output file');
rewrite (outf, 1);
outsize := diskFree (1); { or 2 if it's the "B" drive }
while (outsize > 0) and (size > 0) do begin
amt := sizeof(buf);
if amt > outsize then amt := outsize;
blockRead (inf, buf, amt, amtRead);
blockWrite (outf, buf, amtRead);
dec (outSize, amtRead);
dec (size, amtRead);
end;
closeFile (outf);
until size <= 0;
closeFile (inf);
This is OTTOMH, syntax hasn't been checked, etc. You may want to add other
code to let the user specify the "A" or "B" drive, and/or a naming scheme so
that if disks get out of order it's trapped.
Re-assembling the files is similar: open outf on the hard disk, ask the user
for the first floppy, blockRead/blockWrite from the floppy to the hard disk,
then ask the user for the next floppy, etc. until all floppies are read.
This might help
Cheers
Umulig