加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – FindNext即使仅与faDirectory一起使用也会返回文件名

发布时间:2020-12-15 09:40:07 所属栏目:大数据 来源:网络整理
导读:我试图列出给定目录中的所有目录.我有这个代码: var srec: TSearchRec;begin // folder is some absolute path of a folder if FindFirst(folder + PathDelim + '*',faDirectory,srec) = 0 then try repeat if (srec.Name '.') and (srec.Name '..') then S
我试图列出给定目录中的所有目录.我有这个代码:

var
    srec: TSearchRec;

begin
    // folder is some absolute path of a folder
    if FindFirst(folder + PathDelim + '*',faDirectory,srec) = 0 then
        try
            repeat
                if (srec.Name <> '.') and (srec.Name <> '..') then
                    ShowMessage(srec.Name);
            until FindNext(srec) <> 0;
        finally
            FindClose(srec);
        end;

但由于某种原因,我只收到有关文件名而不是目录的消息.我认为使用faDirectory会使FindFirst和family只返回目录名.我究竟做错了什么?如果我改成它

if FindFirst(folder,srec) = 0 then

然后它只显示文件夹的名称,但不显示绝对路径(相对于文件夹’/ ..’),然后退出.

我意识到我可以通过确保(srec.Attr和faDirectory)= faDirectory来检查它是否是一个目录,但我觉得这是以迂回的方式做事情,应该有一个正确的方法.

解决方法

如果您使用的是delphi xe,请检查 TDirectory.GetDirectories功能.

SysUtils.FindFirst文档可以解答您的问题.

function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer;

The Attr parameter specifies the special files to include in addition to all normal files. Choose from these file attribute constants when specifying the Attr parameter.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读