하위 폴더 가져오기

1723 단어 .Net
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IOSerialize.IO
{
    public class Recursion
    {
        public static List FindAll(string rootPath)
        {
            List dirList = new List();
            DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);//1
            dirList.Add(rootDirectory);

            FindChild(rootDirectory, dirList);

            //DirectoryInfo[] dirChildList = rootDirectory.GetDirectories();//2
            //dirList.AddRange(dirChildList);

            //foreach (var child in dirChildList)
            //{
            //    DirectoryInfo[] dirGrandList = child.GetDirectories();//3
            //    dirList.AddRange(dirGrandList);

            //    foreach (var grand in dirGrandList)
            //    {

            //    }
            //}


            return dirList;
        }

        /// 
        ///  , ,
        ///  , 。。。。
        /// 
        ///  
        ///  
        private static void FindChild(DirectoryInfo parentDirectory, List dirList)
        {
            DirectoryInfo[] dirChildList = parentDirectory.GetDirectories();
            dirList.AddRange(dirChildList);
            if (dirChildList != null && dirChildList.Length > 0)//1  
            {
                foreach (var child in dirChildList)//2  
                {
                    FindChild(child, dirList);
                }
            }
        }
    }
}

좋은 웹페이지 즐겨찾기