博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取指定文件夹及子文件夹中全部文件列表
阅读量:7029 次
发布时间:2019-06-28

本文共 747 字,大约阅读时间需要 2 分钟。

  #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

转载地址:http://dgrxl.baihongyu.com/

你可能感兴趣的文章
句柄类
查看>>
GitLab
查看>>
【常用配置】Spring框架web.xml通用配置
查看>>
[leetcode 240]Search a 2D Matrix II
查看>>
域名指的是这一级目录
查看>>
[Angular] Creating an Observable Store with Rx
查看>>
[转]Porting to Oracle with Entity Framework NLog
查看>>
chmod更改文件的权限
查看>>
oracle 10g/11g RAC 启停归档模式
查看>>
poj3461 Oulipo
查看>>
OAuth2.0学习(1-12)开源的OAuth2.0项目和比较
查看>>
Gitlab,这也就O了???
查看>>
2014 百度之星 1003 题解 Xor Sum
查看>>
Linux中在主机上实现对备机上文件夹及文件的操作的C代码实现
查看>>
iOS 块的简单理解
查看>>
idea中如何配置git以及在idea中初始化git
查看>>
关于JQuery Class选择器的一点
查看>>
POJ3264 Balanced Lineup
查看>>
redis-cli 连接远程服务器
查看>>
emlog通过pjax实现无刷新加载网页--完美解决cnzz统计和javascript失效问题
查看>>