zoukankan      html  css  js  c++  java
  • TDirectory.GetFileSystemEntries获取指定目录下的目录和文件

    使用函数:

    System.IOUtils.TDirectory.GetFileSystemEntries

    所有重载:

    class function GetFileSystemEntries(const Path: string): TStringDynArray;
    class function GetFileSystemEntries(const Path: string;  const Predicate: TFilterPredicate): TStringDynArray;
    class function GetFileSystemEntries(const Path,  SearchPattern: string): TStringDynArray; overload; static;
    class function GetFileSystemEntries(const Path, SearchPattern: string;  const Predicate: TFilterPredicate): TStringDynArray; overload; static;
    class function GetFileSystemEntries(const Path: string;  const SearchOption: TSearchOption; const Predicate: TFilterPredicate): TStringDynArray; overload; static;

    参数说明和TDirectory.GetDirectories一样,只是目录和文件

    异常处理: 目录无效或目录不存在

    示例:

      获取指定目录下所有'a'开头的文件和文件夹

    代码部分:

    var
        sPathOrFile: string;
        fp: TDirectory.TFilterPredicate;
    begin
        fp := function(const Path: string;
              const SearchRec: TSearchRec): Boolean
        begin
            Result := TPath.MatchesPattern(SearchRec.Name, 'a*', False);
            //匹配a开头的文件夹和文件
        end;
        try
            ;
            for sPathOrFile in TDirectory.GetFileSystemEntries('H:	mp', TSearchOption(1), fp) do
                ListBox1.Items.Add(sPathOrFile);
    
            //获取'H:'目录下的所有文件和文件夹(包含子目录递归)
        except
            on e: Exception do
            begin
                MessageDlg(e.ClassName + ' : ' + e.Message, mtError, [mbok], 0);
                Exit;
            end;
    
        end;
    end;
  • 相关阅读:
    Redis配置文件的使用
    WEB请求处理一:浏览器请求发起处理
    Nginx配置文件(nginx.conf)配置详解
    【node】------mongoose的基本使用
    Promise.resolve()与new Promise(r => r(v))
    promise是什么?
    apiDoc
    apiDoc 使用指南
    微信小程序-性能与体验优化
    微信小程序-调取上一页的方法
  • 原文地址:https://www.cnblogs.com/cause/p/3500112.html
Copyright © 2011-2022 走看看