Function F_FileOperation(const Source, Dest: string;ai_flag:integer;abl_Question:Boolean): boolean; {******************************************************** 函数功能:实现对文件的操作 入口 :ai_flag 1,xCOPY //拷贝目录下所有文件,包括子目录 2,xDELETE //删除目录所有文件,包括子目录 3,xMOVE //移动目录所有文件,包括子目录 SourcePath 源目录 DestPath 目标路径 abl_Question: //拷贝时是否出现提示 出口 :1、 成功 -1、失败 时间 :2002-10-1 *********************************************************} var fo: TSHFILEOPSTRUCT; //目录结构 begin FillChar(fo, SizeOf(fo), 0); Case ai_flag of 1: fo.WFunc := FO_COPY; 2: fo.WFunc := FO_DELETE; 3: fo.WFunc := FO_MOVE; 4: fo.WFunc := FO_RENAME; else result := false; end; if abl_Question then fo.fFlags :=FOF_FILESONLY else fo.fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR +FOF_SILENT; with fo do begin Wnd := 0; pFrom := PChar(source+#0); pTo := PChar(Dest+#0); end; Result := (SHFileOperation(fo) = 0); end;
SHFileOperation是可以的 自己写了一个拷贝文件夹的,还不如直接使用SHFileOperation, 记得Uses ShellAPI; var ops:tshfileopstruct; sb,tb:array[0..255] of char; source,target:string; begin source:=sourcefolder.Text; target:=targetfolder.Text; fillchar(sb,sizeof(sb),0); fillchar(tb,sizeof(tb),0); strpcopy(sb,pchar(source)); strpcopy(tb,pchar(target)); with ops do begin wnd:=handle; wfunc:=fo_copy; pfrom:=@sb; pto:=@tb; fAnyOperationsAborted:=true; fflags:={FOF_NOCONFIRMATION or} FOF_NOCONFIRMMKDIR or FOF_MULTIDESTFILES; hnamemappings:=nil; lpszprogresstitle:=nil; end; if shfileoperation(ops)=0 then showmessage('Copy Done'); end;
uses ShellAPIvar Fstr:SHFILEOPSTRUCT; with fstr do begin Wnd:=handle; wFunc:=FO_COPY; pFrom:=pchar(SFileName); pTo:=pchar(DFileName); fFlags:=FOF_FILESONLY; fAnyOperationsAborted:=false; hNameMappings:=nil; lpszProgressTitle:=nil; end; ShFileOperation(fstr);
{********************************************************
函数功能:实现对文件的操作
入口 :ai_flag
1,xCOPY //拷贝目录下所有文件,包括子目录
2,xDELETE //删除目录所有文件,包括子目录
3,xMOVE //移动目录所有文件,包括子目录
SourcePath
源目录
DestPath
目标路径
abl_Question: //拷贝时是否出现提示
出口 :1、 成功
-1、失败 时间 :2002-10-1
*********************************************************}
var
fo: TSHFILEOPSTRUCT; //目录结构
begin
FillChar(fo, SizeOf(fo), 0); Case ai_flag of
1: fo.WFunc := FO_COPY;
2: fo.WFunc := FO_DELETE;
3: fo.WFunc := FO_MOVE;
4: fo.WFunc := FO_RENAME;
else
result := false;
end;
if abl_Question then
fo.fFlags :=FOF_FILESONLY
else
fo.fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR +FOF_SILENT;
with fo do
begin
Wnd := 0;
pFrom := PChar(source+#0);
pTo := PChar(Dest+#0);
end;
Result := (SHFileOperation(fo) = 0);
end;
自己写了一个拷贝文件夹的,还不如直接使用SHFileOperation,
记得Uses ShellAPI;
var
ops:tshfileopstruct;
sb,tb:array[0..255] of char;
source,target:string;
begin
source:=sourcefolder.Text;
target:=targetfolder.Text;
fillchar(sb,sizeof(sb),0);
fillchar(tb,sizeof(tb),0);
strpcopy(sb,pchar(source));
strpcopy(tb,pchar(target));
with ops do
begin
wnd:=handle;
wfunc:=fo_copy;
pfrom:=@sb;
pto:=@tb;
fAnyOperationsAborted:=true;
fflags:={FOF_NOCONFIRMATION or} FOF_NOCONFIRMMKDIR or FOF_MULTIDESTFILES;
hnamemappings:=nil;
lpszprogresstitle:=nil;
end;
if shfileoperation(ops)=0 then showmessage('Copy Done');
end;
Fstr:SHFILEOPSTRUCT; with fstr do
begin
Wnd:=handle;
wFunc:=FO_COPY;
pFrom:=pchar(SFileName);
pTo:=pchar(DFileName);
fFlags:=FOF_FILESONLY;
fAnyOperationsAborted:=false;
hNameMappings:=nil;
lpszProgressTitle:=nil;
end;
ShFileOperation(fstr);
函数旧可以了,非常的简单,具体可以参考《delphi5开发人员指南》