DELPHI如何获取某目录下的所有文件名
//=====================================================================
// 函数名称: 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;
// 函数名称: 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编程
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)