16,748
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.Button1Click(Sender: TObject);
type
TGetFileCount = reference to function(srcPath, srcFileName: string): integer;
var
GFC: TGetFileCount;
begin
GFC := function(srcPath, srcFileName: string): integer
var
FileRec: TSearchrec;
currPath: string;
begin
if srcPath[Length(srcPath)] <> '\' then srcPath := srcPath + '\';
currPath := srcPath + '*.*';
Result := 0;
if FindFirst(currPath, faAnyFile, FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) <> 0) and
(FileRec.Name <> '.') and
(FileRec.Name <> '..') then
begin
Result := Result + GFC(srcPath + FileRec.Name, srcFileName);
end else
if AnsiCompareText(srcFileName, FileRec.Name) = 0 then
Result := Result + 1;
until FindNext(FileRec) <> 0;
end;
ShowMessage(IntToStr(GFC('c:\test', 'aaa.txt')));
end;
编译需要引用单元System.SysUtils和WinAPI.Windows