1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Split and Merger File(s)

Discussion in 'Delphi Programming' started by grgwjy, Apr 15, 2015.

  1. grgwjy
    Offline

    grgwjy DF Member DF Gold User

    Here my old code that i made in 2008, this code to split a huge size of file and merger them again. I made this trick for an idea how to bring a huge file into small size of storage device or send it via eMail that not allow me to send a huge size of file.

    Code:
    unit GSplitMergeFile2008;
    
    interface
    
    uses Classes, SysUtils;
    
    type
     TGSplitMerge2008 = class(TComponent)
      private
       vFileName : TFileName;
       vFileByteSize : integer;
       vFirstSplitFileName : TFileName;
      public
       function SplitFile : boolean; overload;
       function SplitFile(pSource : string; pSplitSize : integer) : boolean; overload;
       function MergeFile : boolean; overload;
       function MergerFile(pDestination,pFirstSplitFileName : string) : boolean; overload;
      published
       property FileName : TFileName
                read vFileName
                write vFileName;
       property FileByteSize : integer
                read vFileByteSize
                write vFileByteSize;
       property FirstSplitFileName : TFileName
                read vFirstSplitFileName
                write vFirstSplitFileName;
     end;
    
    procedure Register;
    
    implementation
    
    function TGSplitMerge2008.SplitFile : boolean;
    var
     fs, ss : TFileStream;
     cnt : integer;
     SplitName : string;
    begin
     Result := true;
     try
      fs := TFileStream.Create(vFileName, fmOpenRead or fmShareDenyWrite);
      try
       for cnt := 1 to Trunc(fs.Size/vFileByteSize) + 1 do
       begin
        SplitName := ChangeFileExt(vFileName, Format('%s%d',['._',cnt]));
        ss := TFileStream.Create(SplitName,fmCreate or fmShareExclusive);
        try
         if fs.Size - fs.Position < vFileByteSize then
          vFileByteSize := fs.Size - fs.Position;
         ss.CopyFrom(fs,vFileByteSize);
        finally
         ss.Free;
        end;
       end;
      finally
       fs.Free;
      end;
     except
      Result := false;
     end;
    end;
    
    function TGSplitMerge2008.SplitFile(pSource : string; pSplitSize : integer) : boolean;
    begin
     vFileName := pSource;
     vFileByteSize := pSplitSize;
     Result := SplitFile;
    end;
    function TGSplitMerge2008.MergeFile : boolean;
    var
     fs, ss : TFileStream;
     cnt : integer;
    begin
     Result := true;
     cnt := 1;
     try
      fs := TFileStream.Create(vFileName,fmCreate or fmShareExclusive);
      try
       while FileExists(vFirstSplitFileName) do
       begin
        ss := TFileStream.Create(vFirstSplitFileName, fmOpenRead or fmShareDenyWrite);
        try
         fs.CopyFrom(ss,0)
        finally
         ss.Free;
        end;
        inc(cnt);
        vFirstSplitFileName := ChangeFileExt(vFirstSplitFileName, Format('%s%d',['._',cnt]));
       end;
      finally
       fs.Free;
      end;
     except
      Result := false;
     end;
    end;
    
    function TGSplitMerge2008.MergerFile(pDestination,pFirstSplitFileName : string) : boolean;
    begin
     vFileName := pDestination;
     vFirstSplitFileName := pFirstSplitFileName;
     Result := MergeFile;
    end;
    
    procedure Register;
    begin
     RegisterComponents('GSoft2008',[TGSplitMergeFile2008]);
    end;
    
    end.
     
  2. kassane
    Online

    kassane Guest

    Thx! :p
    Do you have a source?
     
  3. delphixe8
    Online

    delphixe8 Guest

    [quote pid=116625 dateline=1429121427]>Here my old code that i made in 2008, this code to >split a huge size of file and merger them again. [/quote]
    Reminds me of the times back them when one used to move files in floppy sizes (yes, I'm that old)

    Nice
     
  4. cfpatelsurat
    Online

    cfpatelsurat Guest

    RE:

    thanks
     

Share This Page