• 递归操作文件


            /// <summary>
            /// 找出全部的子文件夹
            /// </summary>
            /// <param name="rootPath">根目录</param>
            /// <returns></returns>
            public static List<DirectoryInfo> GetAllDirectory(string rootPath)
            {
                if (!Directory.Exists(rootPath))
                    return new List<DirectoryInfo>();
    
                List<DirectoryInfo> directoryList = new List<DirectoryInfo>();//容器
                DirectoryInfo directory = new DirectoryInfo(rootPath);//root文件夹
                directoryList.Add(directory);
    
                return GetChild(directoryList, directory);            
            }
    
            /// <summary>
            /// 完成 文件夹--子目录--放入集合
            /// </summary>
            /// <param name="directoryList"></param>
            /// <param name="directoryCurrent"></param>
            /// <returns></returns>
            private static List<DirectoryInfo> GetChild(List<DirectoryInfo> directoryList, DirectoryInfo directoryCurrent)
            {
                var childArray = directoryCurrent.GetDirectories();
                if (childArray != null && childArray.Length > 0)
                {
                    directoryList.AddRange(childArray);
                    foreach (var child in childArray)
                    {
                        GetChild(directoryList, child);
                    }
                }
                return directoryList;
            }
  • 相关阅读:
    检索COM类工厂中CLSID为{00024500-0000-0000-C000-000000000046}的组件时失败
    VSTO 开发中 应用ActionPane、CustomTaskPane
    Thread.Join()的详解
    HBase笔记
    Hive命令详解
    视频地址
    几种表
    如何将数据导入到hive中
    hdfs笔记
    分区表简介
  • 原文地址:https://www.cnblogs.com/LJP-JumpAndFly/p/12018059.html
Copyright © 2020-2023  润新知