我自己软件中的一个函数,送给大家啦!嘿嘿……function TfrmMain.FindDir(Path: String; DirList: TStringList): Boolean;
var
DSearchRec: TSearchRec;
FindResult: integer;
sDir: string;
function IsDirNotation(DirName: String): Boolean;
begin
Result := (DirName = '.') or (DirName = '..');
end;
begin
//获得一个有效的目录名
Path := GetDirectoryName(Path);
//查找第一个匹配的文件
FindResult := FindFirst(Path+'*.*',faDirectory,DSearchRec);
try
//继续查找匹配的文件
while FindResult =0 do
begin
if ((DSearchRec.Attr and faDirectory) = faDirectory) and not IsDirNotation(DSearchRec.Name) then
begin
sDir := copy(Path+DSearchRec.Name,length(edtMainDir.Text)+1,length(Path+DSearchRec.Name));
DirList.Add(GetDirectoryName(sDir));
application.ProcessMessages;
//这里是递归调用
FindDir(Path+DSearchRec.Name,DirList);
end;
FindResult := FindNext(DSearchRec);
end;
if DirList.Count > 0 then result := true else result := false;
finally
FindClose(DSearchRec);
end;
end;
var
DSearchRec: TSearchRec;
FindResult: integer;
sDir: string;
function IsDirNotation(DirName: String): Boolean;
begin
Result := (DirName = '.') or (DirName = '..');
end;
begin
//获得一个有效的目录名
Path := GetDirectoryName(Path);
//查找第一个匹配的文件
FindResult := FindFirst(Path+'*.*',faDirectory,DSearchRec);
try
//继续查找匹配的文件
while FindResult =0 do
begin
if ((DSearchRec.Attr and faDirectory) = faDirectory) and not IsDirNotation(DSearchRec.Name) then
begin
sDir := copy(Path+DSearchRec.Name,length(edtMainDir.Text)+1,length(Path+DSearchRec.Name));
DirList.Add(GetDirectoryName(sDir));
application.ProcessMessages;
//这里是递归调用
FindDir(Path+DSearchRec.Name,DirList);
end;
FindResult := FindNext(DSearchRec);
end;
if DirList.Count > 0 then result := true else result := false;
finally
FindClose(DSearchRec);
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货