文件查找

tjj5203 2010-03-08 11:19:53
我想知道在指定目录下,文件名含关键字"M64"的文件是否存在,并且获取这个文件名
...全文
84 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
haochin 2010-03-08
  • 打赏
  • 举报
回复
新得到该文件夹下所有子文件夹的名字。

然后一个判断是不是含有 'M64'。

获得子文件夹名的方法:

procedure FindDirUnder(strDir: string; IncludeSelf: boolean; var DirList: TStringList);
// 得到StrDir目录下的子目录以DirList返回
procedure FindFileUnder(strDir, ExtName: string; var FileList: TStringList);
// 得到StrDir目录下的所有以ExtFile('.pas')为扩展名的文件 以FileList返回



procedure FindDirUnder(strDir: string; IncludeSelf: boolean; var DirList: TStringList);
var
SRec: TSearchRec;
retval: Integer;
begin
DirList.Clear;
retval := FindFirst(strDir+'\*.*',faDirectory,sRec);
try
while retval = 0 do
begin
if (SRec.Attr and faDirectory) <> 0 then
if (Srec.Name = '.') or (Srec.Name = '..') then
begin
if IncludeSelf then
DirList.Add(Srec.Name)
end else
DirList.Add(Srec.Name);
retval := FindNext(SRec);
end;
finally
FindClose(SRec);
end;
end;

procedure FindFileUnder(strDir,ExtName:string;var FileList:TStringList);
var
SRec: TSearchRec;
retval: Integer;
begin
FileList.Clear;
retval := FindFirst(strDir+'\'+ExtName,faAnyFile,sRec);
try
while retval = 0 do
begin
if (SRec.Attr and faDirectory) = 0 then
FileList.Add(Srec.Name);
retval := FindNext(SRec);
end;
finally
FindClose(SRec);
end;
end;

tjj5203 2010-03-08
  • 打赏
  • 举报
回复
其他的API有没有?
tjj5203 2010-03-08
  • 打赏
  • 举报
回复
引用 1 楼 kfcoffe 的回复:
FindFirst

FindNext

FindClose(sr);


就搞定了

kfcoffe 2010-03-08
  • 打赏
  • 举报
回复
FindFirst

FindNext

FindClose(sr);


就搞定了

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧