delphi 复制文件夹的函数
procedure ShellCopy(const dir1: string; const dir2: string); /////格式shellcopy('d:\1*.*','e:\1\');///windows外壳拷贝
var
f: TSearchRec;
na, sdir: string;
s: TStringList;
i: integer;
fshell: TSHFileOpStruct;
begin
s := TStringList.Create;
//////////////////////
if (not DirectoryExists(dir2)) then CreateDir(dir2);
sdir := dir1;
Delete(sdir, length(sdir) - 2, 3);
if FindFirst(dir1, faAnyFile, f) = 0 then
begin
if (f.Name <> 'database.dat') and (f.Attr <> faDirectory) then
begin
s.Add(f.Name);
end;
repeat
na := f.Name;
FindNext(f);
if (na <> f.Name) and (f.Name <> 'database.dat') and (f.Attr <> faDirectory) then
begin
s.Add(f.Name);
end;
until na = f.Name;
end;
//////////////////////
fshell.Wnd := form1.Handle;
fshell.wFunc := FO_COPY;
fshell.fFlags := FOF_SILENT;
for i := 0 to s.Count - 1 do
begin
fshell.pFrom := pansichar(sdir + s.Strings[i]);
fshell.pTo := pansichar(dir2 + s.strings[i]);
SHFileOperation(fshell);
end;
end;
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。