遍历指定目录及其子目录下所有文件

function ReturnFiles(slFilePath: string):TStringList;
var
  Sr : TSearchRec;
  Err : integer;
begin
  result:=TStringList.Create;
  if slFilePath='' then
    exit;
  if RightStr(slFilePath,1)<>'\' then
    slFilePath:=slFilePath+'\';
  Err:=FindFirst(slFilePath+'*', faAnyFile, Sr) ;
  While (Err = 0) do
  begin
    if (sr.Name[1]<>'.')and ((Sr.Attr and faDirectory) = 0) then
      Result.Add(Sr.Name);
    if ((Sr.Attr and faDirectory) <> 0) AND (Sr.Name[1] <> '.') then
    begin
      ReturnFiles(slFilePath+ sr.Name);
    end;
    Err:=FindNext(Sr) ;
  end ;
  FindClose(Sr);
end;

 

posted @ 2013-10-11 16:15  胖达没有海  阅读(482)  评论(0编辑  收藏  举报