两种遍历所有目录的方法

//递归版本
    static void GetDirectoryTree(ArrayList list, string path)

    {

        list.Add(path);

        string[] paths;

        try

        {

            paths = Directory.GetDirectories(path);

        }

        catch

        {

            return;

        }

        for (int i = 0; i < paths.Length; i++)

            GetDirectoryTree(list, paths[i]);

    }
//列表版本



    static void GetDirectoryTree(ArrayList list, string path)

    {

        string[] paths;

        list.Add(path);

        for (int i = 0; i < list.Count; i++)

        {

            try

            {

                paths = Directory.GetDirectories(list[i].ToString());

            }

            catch

            {

                continue;

            }

            list.AddRange(paths);

        }

    }

猜你喜欢

转载自blog.csdn.net/KAMILLE/article/details/2612939