文件复制问题:
使用坛子中贴出的自定义CopyDirectory()函数实现目录下文件的复制,在Source中可以使用通配符,如*.*可以复制一个目录下的全部文件到 Dest下,包含子目录和子目录下的文件,但如果指定在Source中使用*.rar的通配符,则只复制当前目录下的*.rar文件,而不会搜索子目录下的*.rar文件,
请问有什么方法可以解决??通过穷举法找出每个子目录下的文件再逐个复制?function CopyDirectory(const Source, Dest: string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd :=Application.Handle;
wFunc := FO_COPY;
pFrom := PChar(source+#0);
pTo := PChar(Dest+#0);
fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR+FOF_SILENT;
end;
SHFileOperation(fo);
Result := (SHFileOperation(fo) = 0);
end;
使用坛子中贴出的自定义CopyDirectory()函数实现目录下文件的复制,在Source中可以使用通配符,如*.*可以复制一个目录下的全部文件到 Dest下,包含子目录和子目录下的文件,但如果指定在Source中使用*.rar的通配符,则只复制当前目录下的*.rar文件,而不会搜索子目录下的*.rar文件,
请问有什么方法可以解决??通过穷举法找出每个子目录下的文件再逐个复制?function CopyDirectory(const Source, Dest: string): boolean;
var
fo: TSHFILEOPSTRUCT;
begin
FillChar(fo, SizeOf(fo), 0);
with fo do
begin
Wnd :=Application.Handle;
wFunc := FO_COPY;
pFrom := PChar(source+#0);
pTo := PChar(Dest+#0);
fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR+FOF_SILENT;
end;
SHFileOperation(fo);
Result := (SHFileOperation(fo) = 0);
end;
var
FPath: String;
FS: TSearchRec;
begin
FPath := IncludeTrailingPathDelimiter(ADisk) + IncludeTrailingPathDelimiter(APath) + '*.*';
if FindFirst(FPath + '*.*', faAnyFile, FS) = 0 then
begin
if (FS.Name <> '.') and (FS.Name <> '..') then
begin
if (FS.Attr and faDirectory) = faDirectory then
begin
FindAll(ADisk, IncludeTrailingPathDelimiter(APath) + FS.Name, Strings, AProperty);
end
else
Strings.Add(FS.Name);
end; while FindNext(FS) = 0 do
begin
if (FS.Name <> '.') and (FS.Name <> '..') then
begin
if (FS.Attr and faDirectory) = faDirectory then
begin
FindAll(ADisk, IncludeTrailingPathDelimiter(APath) + FS.Name, Strings, AProperty);
end
else
Strings.Add(FS.Name);
end;
end;
end;
FindClose(FS);
end;