复制目录: ///复制Source整个目录到DEST目录,如果Dest不存在,自动建立,如果DEST存在,那么Source将作为Dest的子目录! //例如如果要复制E:\Temp整个目录到E:\那么代码为: copydirectory('e:\temp','e:\'); ///如果要复制E:\Temp到E:\Test目录下面,那么代码为:CopyDirecotry('E:\Temp','E:\TEST'); function CopyDirectory(const Source, Dest: string): boolean; 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;
参考: uses shellpai;var Source,Dest:String; FData : TShFileOpStruct; begin Source:='c:\sss';//sss为目录 dest:='\\computername\kkk'; //首先建立文件目录 if not DirectoryExists(Dest) then begin if not CreateDir(Dest) then begin MessageDlg('建立目录出现错误!',mtWarning,[mbOK],0); Exit; end; Fdata.pFrom :=PChar(Source); Fdata.pTo := PChar(Dest); Fdata.wFunc := FO_COPY ; Fdata.Wnd := Application.Handle ; Fdata.lpszProgressTitle := 'Wait'; Fdata.fFlags :=FOF_SIMPLEPROGRESS; ShFileOperation(FData); end; end;end;
///复制Source整个目录到DEST目录,如果Dest不存在,自动建立,如果DEST存在,那么Source将作为Dest的子目录!
//例如如果要复制E:\Temp整个目录到E:\那么代码为: copydirectory('e:\temp','e:\');
///如果要复制E:\Temp到E:\Test目录下面,那么代码为:CopyDirecotry('E:\Temp','E:\TEST');
function CopyDirectory(const Source, Dest: string): boolean;
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;
uses shellpai;var
Source,Dest:String;
FData : TShFileOpStruct;
begin
Source:='c:\sss';//sss为目录
dest:='\\computername\kkk';
//首先建立文件目录
if not DirectoryExists(Dest) then
begin
if not CreateDir(Dest) then
begin
MessageDlg('建立目录出现错误!',mtWarning,[mbOK],0);
Exit;
end;
Fdata.pFrom :=PChar(Source);
Fdata.pTo := PChar(Dest);
Fdata.wFunc := FO_COPY ;
Fdata.Wnd := Application.Handle ;
Fdata.lpszProgressTitle := 'Wait';
Fdata.fFlags :=FOF_SIMPLEPROGRESS;
ShFileOperation(FData);
end;
end;end;