zoukankan      html  css  js  c++  java
  • 获取指定文件夹及子文件夹中全部文件列表

      #region 获取指定文件夹及子文件夹中全部文件列表
            /// <summary>
            /// 获取指定文件夹及子文件夹中全部文件列表
            /// </summary>
            /// <param name="directoryPath">指定文件夹的绝对路径</param>
            /// <param name="searchPattern">模式字符串,"*"代表0或N个字符,"?

    "代表1个字符。


            /// 范例:"Log*.xml"表示搜索全部以Log开头的Xml文件。</param>
            /// <param name="isSearchChild">是否搜索子文件夹</param>
            public static string[] GetFileNames(string directoryPath, string searchPattern, bool isSearchChild)
            {
                //假设文件夹不存在,则抛出异常
                if (!IsExistDirectory(directoryPath))
                {
                    throw new FileNotFoundException();
                }


                try
                {
                    if (isSearchChild)
                    {
                        return Directory.GetFiles(directoryPath, searchPattern, SearchOption.AllDirectories);
                    }
                    else
                    {
                        return Directory.GetFiles(directoryPath, searchPattern, SearchOption.TopDirectoryOnly);
                    }
                }
                catch (IOException ex)
                {
                    throw ex;
                }
            }
            #endregion

  • 相关阅读:
    ASP.NET的内置对象 —— Response 对象
    dd命令测试硬盘IO
    Linux netstat命令详解
    tpcc-mysql安装、使用、结果解读
    【MySQL案例】error.log的Warning:If a crash happens thisconfiguration does not guarantee that the relay lo(转)
    mysql5.6主从
    无法远程访问Mysql
    pythonMD5加密
    python随机验证码函数
    log buffer space事件(转)
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6907985.html
Copyright © 2011-2022 走看看