如何实现将一个目录s_dir下的所有文件即*.*(不包括子目录)拷贝到另一个目录下?下面这段程序是从以前的帖子里找到的,可是运行后连子目录也一块拷了,请问该如何修改?谢谢!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
Fos : TSHFileOpStruct;
Buf : array[0..4096] of char;
p : pchar;
sDest : pchar;
begin
FillChar(Buf, sizeof(Buf), #0) ;
p := @buf;
p := StrECopy(p, 'm:\*.*') + 1;
//p := StrECopy(p, 'C:\SecondFile.ext2') + 1;
StrECopy(p, 'm:\*.*') ;
sDest := 'c:\doc\test\';
FillChar(Fos, sizeof(Fos), #0) ;
with Fos do begin
Wnd := Handle;
wFunc := FO_COPY;
pFrom := @Buf;
pTo := sDest;
fFlags := 0;
end;
if ((SHFileOperation(Fos) <> 0) or
(Fos.fAnyOperationsAborted <> false)) then
ShowMessage('用户取消!')
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
Fos : TSHFileOpStruct;
Buf : array[0..4096] of char;
p : pchar;
sDest : pchar;
begin
FillChar(Buf, sizeof(Buf), #0) ;
p := @buf;
p := StrECopy(p, 'm:\*.*') + 1;
//p := StrECopy(p, 'C:\SecondFile.ext2') + 1;
StrECopy(p, 'm:\*.*') ;
sDest := 'c:\doc\test\';
FillChar(Fos, sizeof(Fos), #0) ;
with Fos do begin
Wnd := Handle;
wFunc := FO_COPY;
pFrom := @Buf;
pTo := sDest;
fFlags := 0;
end;
if ((SHFileOperation(Fos) <> 0) or
(Fos.fAnyOperationsAborted <> false)) then
ShowMessage('用户取消!')
end;end.
// 函数名称: CopyFiles
// 功能描述: 拷贝指定目录下的文件
// 参 数: ASour : 源目录
// ADest : 目标目录
// APropty : 文件属性
// 返 回 值:
// 说 明:
//=====================================================================
procedure CopyFiles(const ASour, ADest: string; APropty: String = '*.XML');
var
strSour, strDest: String;
FS: TSearchRec;
begin
strSour := IncludeTrailingPathDelimiter(ASour);
strDest := IncludeTrailingPathDelimiter(ADest);
if FindFirst(strSour + APropty, faAnyFile, FS) = 0 then
begin
if (FS.Name <> '.') and (FS.Name <> '..') then
begin
if (FS.Attr and faDirectory) <> faDirectory then
begin
CopyFile(PChar(strSour + FS.Name), PChar(strDest + FS.Name), False);
end;
end;
while FindNext(FS) = 0 do
begin
if (FS.Name <> '.') and (FS.Name <> '..') then
begin
if (FS.Attr and faDirectory) <> faDirectory then
begin
CopyFile(PChar(strSour + FS.Name), PChar(strDest + FS.Name), False);
end;
end;
end;
end;
FindClose(FS);
end;
请问调用这个过程的时候“APropty“该怎么赋值啊?