2005/10/10 | 分割、合并文件
类别(语言类学习笔记) | 评论(0) | 阅读(97) | 发表于 00:50
unit unitFrmMain;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, FileCtrl;

type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
UpDown1: TUpDown;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
ListBox1: TListBox;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
//选择待分割的文件

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Edit2.Text := OpenDialog1.FileName;
end;
end;

//设置分割后的分卷文件的存储位置

procedure TForm1.Button2Click(Sender: TObject);
var
Dir: string;
begin
if SelectDirectory('选择存储目录:', '', Dir) then
begin
Edit3.Text := Dir + '\';
end;

end;

//分割文件为分卷文件,自动命名

procedure TForm1.Button3Click(Sender: TObject);
var
I, K, Rest, Len: Integer;
AF, BF: TFileStream; //文件流对象
Fn: string; //文件名
Buf: Integer; //单碟容量
begin

if (Edit2.Text = '') or (Edit3.Text = '') then
begin
Beep;
Exit;
end;
//单碟容量计算为字节数

buf := StrToInt(Edit1.Text) * 1024;
I := 1;
try
Af := TFileStream.Create(Edit2.Text, fmOpenRead);
K := Af.Size div Buf;
Rest := Af.Size - K * Buf;
for I := 1 to K do
begin
Fn := Edit3.Text + IntToStr(I) + '.spt'; //文件名
Bf := TFileStream.Create(Fn, fmCreate);
Bf.CopyFrom(Af, Buf);
ListBox1.Items.Add(Fn);
Bf.Free;
end;
if Rest > 0 then
begin
Fn := Edit3.Text + IntToStr(I) + '.spt';
Bf := TFileStream.Create(Fn, fmCreate);
Bf.CopyFrom(Af, Rest);
Bf.Free;
ListBox1.Items.Add(Fn);
end;
finally
AF.Free;
end;

end;

//将分割后的分卷文件在列表框中显示

procedure TForm1.Button4Click(Sender: TObject);
var
I: Integer;
begin
if OpenDialog1.Execute then
for I := 0 to OpenDialog1.Files.Count - 1 do
ListBox1.Items.Add(OpenDialog1.files[I]);
end;

//合并分卷文件并保存合并结果

procedure TForm1.Button5Click(Sender: TObject);
var
Af, Bf: TFileStream; //文件流对象
Fn, Ft: string; //文件名
I: Integer;
begin
if ListBox1.Items.Count = 0 then
begin
Beep;
Exit;
end;
if SaveDialog1.Execute then
begin
Fn := SaveDialog1.FileName;
try
Af := TFileStream.Create(Fn, fmCreate);
for I := 0 to ListBox1.Items.Count - 1 do
begin
Ft := ListBox1.Items[I];
Bf := TFileStream.Create(Ft, fmOpenRead);
Af.CopyFrom(Bf, Bf.Size);
Bf.Free;
end;
finally
Af.Free;
end;
end;
end;

end.
但是不知道为什么对rar文件分割之后再合并,就不能再解压啦。
0

评论Comments