首页 > Windows开发 > 详细

DELPHI如何获取某目录下的所有文件名?

时间:2018-12-21 11:01:17      阅读:158      评论:0      收藏:0      [点我收藏+]

//=====================================================================
// 函数名称: FindPathFiles
// 功能描述: 找指定目录下的文件
// 参    数:  APath   : 路径名称
//            APropty : 属性名称(*.* | *.txt)
//            AFiles  : 文件列表
//            IsAddPath: 是否增加路径
// 作者:    
// 时间:    
// 返 回 值:
// 说    明:
//=====================================================================
procedure FindPathFiles(const APath: string; AFiles: TStrings;
  const APropty: String = ‘*.*‘; IsAddPath: Boolean = False);
var
  FS: TSearchRec;
  FPath: String;
  AddPath: string;
begin
  FPath := IncludeTrailingPathDelimiter(APath);
  AddPath := IfThen(IsAddPath, FPath, ‘‘);
  if FindFirst(FPath + APropty, faAnyFile, FS) = 0 then
  begin
    repeat
    if //(FS.Name <> ‘.‘) and (FS.Name <> ‘..‘) and
       ((FS.Attr and faDirectory) <> faDirectory) then
       AFiles.Add(AddPath + FS.Name);
    until FindNext(FS) <> 0;
    SysUtils.FindClose(FS);
  end;
end;

//=====================================================================
// 函数名称: FindAllFiles
// 功能描述: 找指定目录下的所有文件
// 参    数:  APath    : 路径名称
//            APropty  : 属性名称(*.* | *.txt)
//            AFiles   : 文件列表
//            IsAddPath: 是否增加路径
// 作者:    
// 时间:    
// 返 回 值:
// 说    明:
//=====================================================================
procedure FindAllFiles(const APath: string; AFiles: TStrings;
  const APropty: String = ‘*.*‘; IsAddPath: Boolean = False);
var
  FS: TSearchRec;
  FPath: String;
  AddPath: string;
begin
  FPath := IncludeTrailingPathDelimiter(APath);
  AddPath := IfThen(IsAddPath, FPath, ‘‘);
  if FindFirst(FPath + APropty, faAnyFile, FS) = 0 then
  begin
    repeat
    if (FS.Name <> ‘.‘) and (FS.Name <> ‘..‘) then
      if ((FS.Attr and faDirectory) = faDirectory) then
        FindAllFiles(FPath + FS.Name, AFiles, APropty, IsAddPath)
      else
        AFiles.Add(AddPath + FS.Name);
    until FindNext(FS) <> 0;
    SysUtils.FindClose(FS);
  end;
end;

DELPHI如何获取某目录下的所有文件名?

原文:https://www.cnblogs.com/yumalei/p/10153767.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!