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

delphi – FindFirst应该按字母顺序返回找到的文件吗?

发布时间:2020-12-15 03:51:46 所属栏目:大数据 来源:网络整理
导读:我曾经尝试过FindFirst按字母顺序找到文件,但最近我发现虽然大多数情况下都是如此,但是有些文件不按字母顺序排列. if FindFirst( AProgramPath,faAnyFile,ASearchRec ) = 0 thenrepeat AFilename := ASearchRec.name;until FindNext( ASearchRec ) 0;FindClo
我曾经尝试过FindFirst按字母顺序找到文件,但最近我发现虽然大多数情况下都是如此,但是有些文件不按字母顺序排列.
if FindFirst( AProgramPath,faAnyFile,ASearchRec ) = 0 then
repeat
  AFilename := ASearchRec.name;
until FindNext( ASearchRec ) <> 0;
FindClose( ASearchRec );

在这里的特定文件夹中有大约300个文本文件,但是大约8-10个文件以正确的字母顺序返回.

如果findfirst不按字母顺序返回文件,是否有一种方法可用于按字母顺序对文件夹内容进行排序,以便findfirst按字母顺序返回文件?

问候,

法案

解决方法

FindFirst函数不对搜索结果进行排序,但您可以使用TStringList对文件进行排序.
Procedure GetOrderFiles();
var
 ListFiles : TStringList;
 result    : integer;
 ASearchRec: TSearchRec;
begin
 ListFiles         := TStringList.Create;
 try
   ListFiles.sorted  := True;  
   result        := findFirst(AProgramPath,ASearchRec );
   try
     while result = 0 do
     begin
      if (ASearchRec.name <> '.') and (ASearchRec.name <> '..') then
      ListFiles.add(ASearchRec.name);
      result:=FindNext(ASearchRec );
     end;
   finally 
     FindClose(ASearchRec );
   end;  

   //process your files

   //....
 finally
    ListFiles.free;
 end;
end;

(编辑:李大同)

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

    推荐文章
      热点阅读