DELPHI切割文件代码

//Splitting Files
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);  //Wanted SplitSize
   i := 0;
   InStream  := TFileStream.Create(OpenDialog1.FileName, fmOpenRead );
   try
     while (InStream.Position < InStream.Size) do
     Begin
       s := IntToStr(I);                   //Building numeric suffix
       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(SaveDialog1.FileName+ s,fmCreate );
       try
         OutStream.CopyFrom(InStream,RealToWrite) ;
         Inc(i);
       finally
         OutStream.Free;
       end;
     end;
   Finally
     InStream.Free;
   end;
 end;
end;
end;

//concanating files
procedure TForm1.Button2Click(Sender: TObject);
var
i : Integer;
InStream, OutStream : TFileStream;
SourcePath, FragName, S : String;
begin
Opendialog1.Title := 'Select any Fragmented File';
if Opendialog1.Execute then
begin
 SourcePath := ExtractFilePath(Opendialog1.FileName);
 FragName := ExtractFileName(Opendialog1.FileName);
 SaveDialog1.Title := 'Select Dir and input the FileName with Suffix';
 If SaveDialog1.Execute then
 begin
   i := 0;
   s := IntToStr(I);
   while Length(s) < 3 do s := '0'+s;
   s := '.'+s;
   FragName := ChangeFileExt(FragName, s);
   If FileExists(SourcePath+FragName) then
   begin
     OutStream := TFileStream.Create(Savedialog1.FileName, fmCreate);
     try
       While FileExists(SourcePath+FragName) do
       Begin
         InStream  := TFileStream.Create(SourcePath+FragName,f mOpenRead) ;
         try
           OutStream.CopyFrom(InStream,0);
           Inc(i);
           s := IntToStr(I);
           while Length(s) < 3 do s := '0'+s;
           s := '.'+s;
           FragName := ChangeFileExt(FragName, s);
         finally
           InStream.Free;
         end;
       end;
     finally
       OutStream.Free;
     end;
   end;
 end;
end;
end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值