有关目录拷贝(50分)

  • 主题发起人 主题发起人 royal666
  • 开始时间 开始时间
R

royal666

Unregistered / Unconfirmed
GUEST, unregistred user!
我想实现目录拷贝时,如果文件已存在,则先删除再拷贝,程序如下:<br>function TForm1.CopyDir(sDirName:String;sToDirName:String):Boolean; //&amp;iquest;&amp;frac12;±&amp;acute;&amp;Acirc;·&amp;frac34;&amp;para;&amp;pound;&amp;not;&amp;Icirc;&amp;THORN;&amp;acute;í&amp;Icirc;ó<br>var<br>&nbsp; frombuf,tobuf: array [0..128] of char;<br>&nbsp; opstruct:Tshfileopstruct;<br>&nbsp; p:string;<br>&nbsp; Taille: Int64;<br>&nbsp; size:integer;<br>begin<br>&nbsp; Fillchar(frombuf,sizeof(frombuf),0);<br>&nbsp; Fillchar(tobuf,sizeof(tobuf),0);<br>&nbsp; Strpcopy(frombuf,Label1.Caption);<br>&nbsp; Strpcopy(tobuf,Label2.Caption);<br><br>&nbsp;<br>&nbsp; &nbsp;Label3.caption:=inttostr(freespace(Label2.caption));<br>&nbsp;<br>&nbsp; if not DirectoryExists(label2.caption+'/'+extractfilename(Label1.caption)) then//&amp;acute;<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with opstruct do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wnd:=handle;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wfunc:=fo_copy;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pfrom:=@frombuf;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pto:=@tobuf;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fFlags:=fof_noconfirmation ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fanyoperationsaborted:=False;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hnamemappings:=nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpszprogresstitle:=nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShFileOperation(OpStruct );<br>&nbsp; end<br>&nbsp; else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (messagebox(handle,pchar('文件存在,覆盖?'),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pchar('文件存在!'),MB_YESNO + MB_DEFBUTTON1)=IDNo)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;then &nbsp;exit<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p:=Label2.caption+'/'+extractfilename(Label1.caption);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with opstruct do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wnd:=handle;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wfunc:=fo_delete;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pfrom:=pchar(p);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fFlags:=fof_noconfirmation ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fanyoperationsaborted:=False;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hnamemappings:=nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpszprogresstitle:=nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SHFileOperation( opstruct ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with opstruct do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wnd:=handle;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wfunc:=FO_copy;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pfrom:=@frombuf;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pto:=@tobuf;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fFlags:=fof_noconfirmation ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fanyoperationsaborted:=False;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hnamemappings:=nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpszprogresstitle:=nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShFileOperation(OpStruct );<br><br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>end;<br>1。当第一次拷贝目录时,可正确运行,但一旦重新运行此程序,即不该源目录与目的目录<br>&nbsp; &nbsp;就会出错,为什么?<br>
 
后退
顶部