以下为拷录整个文件夹: procedure TForm1.copyPathFile(strSourFilePath:string;DeFieldpath:string);//将一个文件夹内文件复制到另外一个文件夹内 var OpStruc:TSHFileOpStruct; FromBuf,ToBuf:Array[0..128] of Char; begin try FillChar(FromBuf,Sizeof(FromBuf),0); FillChar(ToBuf,Sizeof(ToBuf),0); StrPCopy(FromBuf,Pchar(strSourFilePath)); //strSourFilePath StrPCopy(ToBuf,Pchar(DeFieldpath)); with OpStruc do begin Wnd:=handle; wFunc:=FO_COPY; pFrom:=@FromBuf; pTo:=@ToBuf; fFlags:=FOF_NOCONFIRMATION or FOF_MULTIDESTFILES or FOF_SIMPLEPROGRESS;// or FOF_RENAMEONCOLLISION; fAnyOperationsAborted:=False; hNameMappings:=nil; lpszProgressTitle:=nil; end; if SHFileOperation(OpStruc)=0 then begin end; except raise Exception.Create('错误'); end; end; 只要在另一个线程中设计用行了。
procedure TForm1.copyPathFile(strSourFilePath:string;DeFieldpath:string);//将一个文件夹内文件复制到另外一个文件夹内
var
OpStruc:TSHFileOpStruct;
FromBuf,ToBuf:Array[0..128] of Char;
begin
try
FillChar(FromBuf,Sizeof(FromBuf),0);
FillChar(ToBuf,Sizeof(ToBuf),0);
StrPCopy(FromBuf,Pchar(strSourFilePath));
//strSourFilePath
StrPCopy(ToBuf,Pchar(DeFieldpath));
with OpStruc do
begin
Wnd:=handle;
wFunc:=FO_COPY;
pFrom:=@FromBuf;
pTo:=@ToBuf;
fFlags:=FOF_NOCONFIRMATION or FOF_MULTIDESTFILES or FOF_SIMPLEPROGRESS;// or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted:=False;
hNameMappings:=nil;
lpszProgressTitle:=nil;
end;
if SHFileOperation(OpStruc)=0 then
begin
end;
except
raise Exception.Create('错误');
end;
end;
只要在另一个线程中设计用行了。
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd := 0;
wFunc := FO_COPY;
pFrom := PChar(source+#0);
pTo := PChar(Dest+#0);
fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR ;
end;
Result := (SHFileOperation(fo) = 0);
end;