• 获取指定文件夹及子文件夹中全部文件列表


      #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

  • 相关阅读:
    洛谷—— P2234 [HNOI2002]营业额统计
    BZOJ——3555: [Ctsc2014]企鹅QQ
    CodeVs——T 4919 线段树练习4
    python(35)- 异常处理
    August 29th 2016 Week 36th Monday
    August 28th 2016 Week 36th Sunday
    August 27th 2016 Week 35th Saturday
    August 26th 2016 Week 35th Friday
    August 25th 2016 Week 35th Thursday
    August 24th 2016 Week 35th Wednesday
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6907985.html
Copyright © 2020-2023  润新知