主题:想要找delphi遍历文件夹的资料...
yangjun33
[专家分:20] 发布于 2006-10-18 16:26:00
请教各位.在哪里可以找到这样的资料啊....我是新手,网上的代码不容易看得懂...
回复列表 (共1个回复)
沙发
aizaixiiii [专家分:2130] 发布于 2006-10-19 09:14:00
{用递归的方法遍历文件}
function EnumFileInRecursion(path: PChar;vFileList:TStrings): Longint; stdcall;
var
searchRec: TSearchRec;
found: Integer;
tmpStr: string;
begin
vFileList.Clear;
Result := 0; //查找结果(文件数)
tmpStr := StrPas(path) + '\*.*';
found := FindFirst(tmpStr, faAnyFile, searchRec);//第一个文件或目录
while found = 0 do
begin
if (searchRec.Attr and faDirectory) <> 0 then
begin
if (searchRec.Name <> '.') and (searchRec.Name <> '..') then
begin
tmpStr := StrPas(path) + '\' + searchRec.Name;
Result := Result + EnumFileInRecursion(PChar(tmpStr),vFileList);//递归调用
end;
end
else begin
Result := Result + 1;
//把找到的文件加到Memo控件
vFileList.Add(StrPas(path) + '\' + searchRec.Name);
end;
//查找下一个文件或目录
found := FindNext(searchRec);
end;
//释放资源
FindClose(searchRec);
end;
我来回复