C#技术百科
问问你的心你有没有信心 做事情要专一坚定,执着

递归删除空文件夹

 public void DeleteEmptyDir(string path)
        {
            DirectoryInfo dis = new DirectoryInfo(path);
       
            if (dis.GetDirectories().Length > 0)
            {
                for (int i = 0; i < dis.GetDirectories().Length; i++)
                {
                    DeleteEmptyDir(dis.GetDirectories()[i].FullName);
                }
            }
            FileInfo[] files = dis.GetFiles();
            if (files.Length < 1 && dis.GetDirectories().Length < 1)
            {
                dis.Delete();

            }


        }

posted on 2009-07-15 12:09  王德田  阅读(264)  评论(0编辑  收藏  举报