用api copy目录的问题(100分)

  • 主题发起人 主题发起人 Laird
  • 开始时间 开始时间
L

Laird

Unregistered / Unconfirmed
GUEST, unregistred user!
&nbsp; &nbsp; dir.Wnd := Handle ;<br>&nbsp; &nbsp; &nbsp; dir.wFunc :=FO_COPY &nbsp; &nbsp;;<br>&nbsp; &nbsp; &nbsp; dir.pFrom := Pchar('c:/test/*.*');<br>&nbsp; &nbsp; &nbsp; dir.pTo := pchar('c:/abc' );<br>&nbsp; &nbsp; &nbsp; SHFileOperation(dir) ;<br><br>&nbsp; &nbsp; &nbsp;dir.Wnd := Handle ;<br>&nbsp; &nbsp; &nbsp; dir.wFunc :=FO_COPY &nbsp; &nbsp;;<br>&nbsp; &nbsp; &nbsp; dir.pFrom := Pchar('c:/test1/*.*');<br>&nbsp; &nbsp; &nbsp; dir.pTo := pchar('c:/abcd' );<br>&nbsp; &nbsp; &nbsp; SHFileOperation(dir) ;<br>程序里面有两个拷贝目录程序的话,第二个很难成功。为什么
 
说明白一点,是不是'c:/test1/*.*下面还有子目录,可能得自己写一个函数递归调用了
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Edit2: TEdit;<br>&nbsp; &nbsp; Edit3: TEdit;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>uses ShellAPI;<br><br>procedure CopyDirectoryTree(AHandle: THandle; Src, Dest: String);<br>var<br>&nbsp; SHFileOpStruct: TSHFileOpStruct;<br>&nbsp; FromDir: PChar;<br>&nbsp; ToDir: PChar;<br>begin<br>&nbsp; GetMem(FromDir, Length(Src) + 2);<br>&nbsp; try<br>&nbsp; &nbsp; GetMem(ToDir, Length(Dest) + 2);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; FillChar(FromDir^, Length(Src) + 2, 0);<br>&nbsp; &nbsp; &nbsp; FillChar(ToDir^, Length(Dest) + 2, 0);<br>&nbsp; &nbsp; &nbsp; StrCopy(FromDir, PChar(Src));<br>&nbsp; &nbsp; &nbsp; StrCopy(ToDir, PChar(Dest));<br>&nbsp; &nbsp; &nbsp; with SHFileOpStruct do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Wnd &nbsp; &nbsp;:= AHandle; &nbsp; // Assign the window handle<br>&nbsp; &nbsp; &nbsp; &nbsp; wFunc &nbsp;:= FO_COPY; &nbsp;// Specify a file copy<br>&nbsp; &nbsp; &nbsp; &nbsp; pFrom &nbsp;:= FromDir;<br>&nbsp; &nbsp; &nbsp; &nbsp; pTo &nbsp; &nbsp;:= ToDir;<br>&nbsp; &nbsp; &nbsp; &nbsp; fFlags := FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;<br>&nbsp; &nbsp; &nbsp; &nbsp; fAnyOperationsAborted := False;<br>&nbsp; &nbsp; &nbsp; &nbsp; hNameMappings := nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; lpszProgressTitle := nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; if SHFileOperation(SHFileOpStruct) &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; FreeMem(ToDir, Length(Dest) + 2);<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; FreeMem(FromDir, Length(Src) + 2);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; CopyDirectoryTree(Handle, Edit1.Text, Edit2.Text);<br>&nbsp; CopyDirectoryTree(Handle, Edit1.Text, Edit3.Text);<br>end;<br><br>end.<br>
 
谢了,对不起晚了两天结
 
接受答案了.
 

Similar threads

V
回复
7
查看
176
visual_cjiajia
V
回复
20
查看
423
龙石佛
后退
顶部