View Single Post
  #4  
Old 07-02-2018, 08:11 PM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 198
Default

the split code would be something like this (untested)
Code:
procedure TForm1.SplitFile(const TheFile: String);
var
  maxSplitPart: Integer;
  InFS: TFileStream;
  OutFS: TFileStream;
  I: Integer;
  FileName: String;
  FileWOExt: String;
  FilePath: String;
  OutFile: String;
begin
  maxPartSize := 300000; //300 kb in bytes
  FilePath := ExtractFilePath(TheFile);
  FileName := ExtractFileName(TheFile);
  FileWOExt := ChangeFileExt(FileName, '');
  I := 1;
  Done := False;
  While Not Done do
  begin
    InFS := TFileStream.Create(TheFile, fmOpenRead);
    try
      OutFile := FilePath + FileWOExt + '.Part' + IntToStr(I);
      Inc(I);
      OutFS := TFileStream.Create(OutFile, fmCreate);
      try
        if maxPartSize < (InFS.Size - InFS.Position)
          OutFS.CopyFrom(InFS, maxSplitPart)
        else
        begin
          OutFS.CopyFrom(InFS, InFS.Size - InFS.Position);
          Done := True;
        end;
      finally
        OutFS.Free;
      end;
    finally
      InFS.Free;
    end;
  end;
end;
Reply With Quote