以下程序调试通过!我将所有文件都压缩成1.36M!(你可以修改大小)<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, Math, StdCtrls, ComCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> Label1: TLabel;<br> Edit1: TEdit;<br> Button3: TButton;<br> ProgressBar1: TProgressBar;<br> Button4: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure Button3Click(Sender: TObject);<br> procedure Button4Click(Sender: TObject);<br> private<br> { Private declarations }<br> procedure InitPack(ss:string); //初始化打包文件<br> procedure PackFile(ss:string); //将文件打包。即文件名为ss的文件复制到打包文件中<br> procedure DePackFile(ss:string);<br> procedure BackUpto(ss:string);<br> function chkdisk(drive:byte;bbsize:longint):boolean;<br> function chkfile(ss:string):boolean;<br><br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>uses Unit2;<br><br>{$R *.dfm}<br>function Tform1.chkfile(ss:string):boolean;<br>var bn:integer;<br>begin<br> result:=true;<br> while fileexists(ss)=false do<br> begin<br> bn:=messagedlg('备份文件不存在!继续吗?',mtwarning,[mbyes,mbno],0);<br> if bn<>mryes then<br> begin<br> result:=false;<br> break;<br> end;<br> end;<br>end;<br><br>procedure Tform1.InitPack(ss:string); //初始化打包文件<br>var vf:File;<br>begin<br>assignfile(vf,ss);<br>rewrite(vf,1);<br>closefile(vf);<br>end;<br><br>procedure Tform1.packfile(ss:string);//将文件打包。即文件名为ss的文件复制到打包文件中<br>var rf,pf:File;<br> fsize:longint;<br> numread,numwrite:integer;<br> ss1,ss2,ss3:string[100];<br> buf:array[1..2048]of char;<br>begin<br>assignfile(pf,'d:/mypack.pak');//分配打包文件<br>assignfile(rf,ss); //分配被打包文件<br>reset(pf,1); //打开打包文件<br>reset(rf,1); //打开被打包文件<br>fsize:=filesize(pf); //获取打包文件尺寸<br>seek(pf,fsize); //文件指针移至文件尾<br>fsize:=filesize(rf); //获取被打包文件尺寸<br>seek(rf,0); //文件指针移至文件尾<br>ss1:='CHANGE'; //标志<br>ss2:=ss;<br>str(fsize,ss3);<br>blockwrite(pf,ss1,10);<br>blockwrite(pf,ss2,30);<br>blockwrite(pf,ss3,20);<br>form1.Canvas.TextOut(50,200,'文件 '+ss+' 正在打包!'); //******<br>repeat //复制文件<br> blockread(rf,buf,sizeof(buf),numread);<br> blockwrite(pf,buf,numread,numwrite);<br>until (numread=0)or(numwrite<>numread);<br>closefile(pf);<br>closefile(rf);<br>end;<br><br>procedure Tform1.BackUpto(ss:string);//打包文件ss复制到备份目录,mysize<br>var sf,df:File;<br> nnn,nn,basesize,srcfilesize:longint;<br> dnum,vi,bn:integer;<br> ss1:string[200];<br> ssdnum,sste,ssattr:string[20];<br> vbyte:char;<br> buf:array[1..2048]of char;<br>begin<br>assignfile(sf,ss);<br>reset(sf,1);<br>srcfilesize:=filesize(sf);<br>basesize:=1430000; //定义软盘的大小<br>dnum:=ceil(srcfilesize/basesize); //计算所需的软盘数量<br>str(dnum,ssdnum);<br>randomize; //启动随机数产生器<br>vi:=random(1000); //产生一个随机数<br>str(vi,ssattr);<br>for vi:=1 to dnum do //复制到软盘或其他目录<br> begin<br> str(vi,sste);<br> sste:=trim(sste);<br> if (edit1.text='A:') or (edit1.text='A:/') or (edit1.text='a:') or (edit1.text='a:/') then<br> begin<br> ss1:='共需'+ssdnum+'张盘,请插入第'+sste+'张盘。';<br> bn:=messagedlg(ss1,mtinformation,[mbyes,mbno],0);<br> if bn<>mryes then break;<br> end;<br> ss1:=uppercase(trim(edit1.text));<br> vbyte:=ss1[1];<br> bn:=ord(vbyte)-ord('A')+1;<br> if chkdisk(bn,basesize)=false then break;<br> ss1:=trim(edit1.text)+'/xx'+sste+'disk.bak';<br> assignfile(df,ss1);<br> rewrite(df,1);<br> ss1:='XXSOFT001';<br> blockwrite(df,ss1,16);<br> blockwrite(df,ssdnum,16);<br> blockwrite(df,ssattr,16);<br> srcfilesize:=basesize;<br> repeat<br> if srcfilesize>2040 then<br> begin<br> nn:=2040;<br> srcfilesize:=srcfilesize-2040;<br> end<br> else<br> begin<br> nn:=srcfilesize;<br> srcfilesize:=0;<br> end;<br> blockread(sf,buf,nn,nnn);<br> blockwrite(df,buf,nnn);<br> until(srcfilesize<=0);<br> closefile(df);<br> progressbar1.StepBy(floor(70/dnum));<br> end;<br> closefile(sf);<br>end;<br><br>procedure Tform1.DePackFile(ss:string); //解包<br>var sf,df:file;<br> ss1,ss2,ss3:string[40];<br> fsize:longint;<br> numread,numwrite,nn:integer;<br> buf:array[1..2048]of char;<br>begin<br> assignfile(sf,ss);<br> reset(sf,1);<br> while not eof(sf) do<br> begin<br> blockread(sf,ss1,10,nn);<br> blockread(sf,ss2,30,nn);<br> blockread(sf,ss3,20,nn);<br> if nn<20 then<br> begin<br> showmessage('No size');<br> closefile(sf);<br> exit;<br> end;<br> fsize:=strtoint(ss3);<br> if ss1<>'CHANGE' then<br> begin<br> showmessage('No CHANGE');<br> closefile(sf);<br> exit;<br> end;<br> assignfile(df,ss2);<br> rewrite(df,1);<br> repeat<br> if fsize>2000 then<br> begin<br> nn:=2000;<br> fsize:=fsize-2000;<br> end<br> else<br> begin<br> nn:=fsize;<br> fsize:=0;<br> end;<br> blockread(sf,buf,nn,numread);<br> blockwrite(df,buf,numread,numwrite);<br> until (fsize=0)or(numwrite<>numread);<br> closefile(df);<br> end;<br> closefile(sf);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>progressbar1.Min:=0;<br>progressbar1.Max:=100;<br>initpack('d:/mypack.pak');<br>packfile('d:/1.XLs');<br>packfile('d:/2.XLs');<br>packfile('d:/3.XLs');<br>packfile('d:/4.XLs');<br>packfile('d:/5.XLs');<br>packfile('d:/6.XLs');<br>packfile('d:/7.XLs');<br>packfile('d:/8.XLs');<br>packfile('d:/9.XLs');<br>packfile('d:/10.XLs');<br>packfile('d:/11.XLs');<br>packfile('d:/12.XLs');<br>backupto('d:/mypack.pak');<br>form1.Canvas.TextOut(50,200,' ');<br>button2.SetFocus;<br>end;<br><br>function Tform1.chkdisk(drive:byte;bbsize:longint):boolean;//软盘检查,成功返回真。<br>var bn,chk:integer;<br> mysize,sup:longint;<br>begin<br> result:=true;<br> chk:=0;<br> while chk=0 do<br> begin<br> mysize:=diskfree(drive);<br> if mysize=-1 then<br> begin<br> bn:=messagedlg('未插入盘,请插入!',mtwarning,[mbyes,mbno],0);<br> if bn=mryes then continue<br> else<br> begin<br> result:=false;<br> break;<br> end;<br> end<br> else<br> begin<br> sup:=diskfree(drive) div 1000000;<br> if sup<1.36 then<br> begin<br> bn:=messagedlg('磁盘空间不够,请插入另一张盘!',mtwarning,[mbyes,mbno],0);<br> if bn=mryes then continue<br> else<br> begin<br> result:=false;<br> break;<br> end;<br> end<br> else<br> break;<br> end;<br> end;<br> end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>close;<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br>form2.Show;<br>end;<br><br>procedure TForm1.Button4Click(Sender: TObject);<br>var sf,df:file;<br> ss:string[200];<br> ss1,ssattr:string[30];<br> numread,numwrite,bn,nn:integer;<br> buf:array[1..2048]of char;<br>begin<br>ss:=trim(edit1.Text)+'/xx1disk.bak';<br>if fileexists(ss)=false then<br> begin<br> messagedlg('备份文件不存在!',mtwarning,[mbok],0);<br> exit;<br> end;<br>assignfile(df,'d:/mypack.pak');<br>rewrite(df,1);<br>assignfile(sf,ss);<br>reset(sf,1);<br>blockread(sf,ss1,16);<br>if ss1<>'XXSOFT001' then<br> begin<br> messagedlg('不是该系统的备份文件!',mtwarning,[mbok],0);<br> closefile(sf);<br> exit;<br> end;<br>blockread(sf,ss1,16);<br>nn:=strtoint(ss1);<br>blockread(sf,ssattr,16);<br>repeat<br> blockread(sf,buf,sizeof(buf),numread);<br> blockwrite(df,buf,numread,numwrite);<br>until (numread=0)or(numwrite<>numread);<br>closefile(sf);<br> if nn>1 then<br> begin<br> for bn:=2 to nn do<br> begin<br> if (edit1.text='A:') or (edit1.text='A:/') or (edit1.text='a:') or (edit1.text='a:/') then<br> messagedlg('请插入第'+inttostr(bn)+'张盘!',mtinformation,[mbok],0);<br> ss:=trim(edit1.Text)+'/xx'+trim(inttostr(bn))+'disk.bak';<br> if chkfile(ss)=false then break;<br> assignfile(sf,ss);<br> reset(sf,1);<br> blockread(sf,ss1,16);<br> if ss1<>'XXSOFT001' then<br> begin<br> messagedlg('不是该系统的备份文件!',mtwarning,[mbok],0);<br> closefile(sf);<br> closefile(df);<br> exit;<br> end;<br> blockread(sf,ss1,16);<br> blockread(sf,ss1,16);<br> if ss1<>ssattr then<br> begin<br> messagedlg('文件xx'+inttostr(bn)+'disk.bak与其它文件不是同一次的备份文件!',mtwarning,[mbok],0);<br> closefile(sf);<br> closefile(df);<br> exit;<br> end;<br> repeat<br> blockread(sf,buf,sizeof(buf),numread);<br> blockwrite(df,buf,numread,numwrite);<br> until (numread=0)or(numwrite<>numread);<br> closefile(sf);<br> end;<br> end;<br>closefile(df);<br>depackfile('d:/mypack.pak');<br>button2.SetFocus;<br>end;<br><br>end.