dengan Delphi 7 !? Tentu saja bisa!Ayo ikutin langkah-langkahnya.
//function split function SplitFile(namaFile : TFileName; ukuranFile : Integer; ProgressBar : TsGauge) : Boolean; //anda bisa mengganti TsGauge dengan TProgressBar var i : Word; fs, sStream: TFileStream; //variabel yang dibutuhkan namaFileSplit,ext: String; begin ProgressBar.Progress := 0; //mengeset nilai progress bar 0 , bila menggunakan TProgressBar , gunakan properties posistion fs := TFileStream.Create(namaFile, fmOpenRead or fmShareDenyWrite); //membuat fileStream baru lalu di assign ke fs try for i := 1 to Trunc(fs.Size / ukuranFile) + 1 do begin ext:=ExtractFileExt(namaFile); //mendapatkan extensi sebelum di split namaFileSplit := ChangeFileExt(namaFile+ext,'.'+FormatFloat('000', i)); //mengganti extensi terurut angka sStream := TFileStream.Create(namaFileSplit, fmCreate or fmShareExclusive); try if fs.Size - fs.Position < ukuranFile then ukuranFile := fs.Size - fs.Position; sStream.CopyFrom(fs, ukuranFile); ProgressBar.Progress := Round((fs.Position / fs.Size) * 100);//menggerakan progress bar finally sStream.Free; //membebaskan stream end; end; finally fs.Free;//membebaskan fs/stream end; end;
procedure TForm1.Button1Click(Sender: TObject); begin SplitFile(FileYangAkanDiSplit,UkuranSplitPerFile, ProgressBar1); //untuk ukuranSplitPerFile bertipe integer dan ukurannya bytes,jadi bila di isi 1000000 bytes sama dengan 1 MB end;
//function join file function joinFiles(namaFile, joinNamaFile : TFileName) : Boolean; var i: integer; fs, sStream: TFileStream; filenameOrg: String; begin i := 1; fs := TFileStream.Create(joinNamaFile, fmCreate or fmShareExclusive); try while FileExists(namaFile) do begin sStream := TFileStream.Create(namaFile, fmOpenRead or fmShareDenyWrite); try fs.CopyFrom(sStream, 0); finally sStream.Free; end; Inc(i); namaFile := ChangeFileExt(namaFile, '.'+ FormatFloat('000', i)); end; finally fs.Free; end; end;
procedure TForm1.Button2Click(Sender: TObject); begin joinFiles(fileYangAkanDiJoin,outputFileYangTelahDiJoin); end;
3 komentar:
gan bagaimana algoritma hjsplit dengan visual basic..
tks
mas ada aplikasi cuti karyawan gak...???
sedot lagi gan :D
Posting Komentar