您现在的位置:首页 >> 硬件系统 >> 硬件系统 >> 内容

Delphi中遍历目录和遍历目录及子目录函数

时间:2011/9/3 15:19:45 点击:

  核心提示:function GetFilenames(FilePath,ExtMask: String):TStrings; //遍历目录var FileRec :TSearchrec;begin if Dir...
function GetFilenames(FilePath,ExtMask: String):TStrings;   //遍历目录
var
  FileRec :TSearchrec;
begin
  if DirectoryExists(FilePath) then
  begin
    if FilePath[Length(FilePath)] <> '\' then FilePath := FilePath + '\';
    Result := TStringList.Create;
    if FindFirst(FilePath + ExtMask,faAnyfile,FileRec) = 0 then
    repeat
      if (FileRec.Attr and faDirectory) = 0 then
          Result.Add(FilePath + FileRec.Name);
    until FindNext(FileRec) <> 0;
    FindClose(FileRec);
  end;
end;

function GetFilenamesEx(FilePath,ExtMask :String):TStrings;   //遍历目录及子目录
var
  FileRec :TSearchrec;
begin
  if DirectoryExists(FilePath) then
  begin
    if FilePath[Length(FilePath)] <> '\' then FilePath := FilePath + '\';
    Result := TStringList.Create;
    if FindFirst(FilePath + ExtMask,faAnyfile,FileRec) = 0 then
    repeat
      if (FileRec.Attr and faDirectory) <> 0 then
      begin
        if (FileRec.Name<> '.') and (FileRec.Name  <> '..') then
          Result.AddStrings(GetFilenames(FilePath + FileRec.Name + '\',ExtMask));
        end
      else Result.Add(FilePath + FileRec.Name);
    until FindNext(FileRec) <> 0;
    FindClose(FileRec);
  end;
end;

Tags:目录 函数 
作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号