zoukankan      html  css  js  c++  java
  • DELPHI XE2 遍历子目录及文件《转》

    function MakeFileList(Path,FileExt:string):TStringList ;
    var
      sch:TSearchrec;
    begin
      Result:=TStringlist.Create;
    
      if rightStr(trim(Path), 1) <> '' then
        Path := trim(Path) + ''
      else
        Path := trim(Path);
    
      if not DirectoryExists(Path) then
      begin
        Result.Clear;
        exit;
      end;
    
      if FindFirst(Path + '*', faAnyfile, sch) = 0 then
      begin
        repeat
           Application.ProcessMessages;
           if ((sch.Name = '.') or (sch.Name = '..')) then Continue;
           if DirectoryExists(Path+sch.Name) then
           begin
             Result.AddStrings(MakeFileList(Path+sch.Name,FileExt));
           end
           else
           begin
             if (UpperCase(extractfileext(Path+sch.Name)) = UpperCase(FileExt)) or (FileExt='.*') then
             Result.Add(Path+sch.Name);
           end;
        until FindNext(sch) <> 0;
        FindClose(sch);
      end;
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    var
      I : integer;
    begin
      lst1.Items := MakeFileList(ExtractFilePath(Application.ExeName)+'Report','.fr3');
      for I := 0 to lst1.Count -1 do
        begin
          lst1.Items[I] := StringReplace(StringReplace(lst1.Items[I],ExtractFilePath(Application.ExeName)+'Report','',[rfReplaceAll, rfIgnoreCase]),'','',[rfReplaceAll, rfIgnoreCase]);
        end;
      if lst1.Items[0] = '' then
        lst1.Items.Delete(0);
    
        cbb1.Clear;
      for I := 0 to lst1.Count -1 do
        begin
          cbb1.Items.Add(lst1.Items[I]);
          cbb1.ItemIndex := 0;
        end;
      lst1.Clear;
    end;
  • 相关阅读:
    C macro : the " do { ... } while(0)" magic
    sscanf()函数
    poj-1200-hash-
    hduoj-1735 简单的贪心算法
    hduoj -2570-简单的贪心算法入门
    分治算法应用-最近点对的最小距离-hdu 1007 Quoit Design
    分治算法(转载)
    快速幂总结
    poj 1065 贪心算法
    toj ~3988~递归二叉树三种遍历的转换
  • 原文地址:https://www.cnblogs.com/LceMeaning/p/4195970.html
Copyright © 2011-2022 走看看