递归删除空文件夹

递归删除空文件夹

 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();

            }


        }

你可能感兴趣的:(文件夹)