void DeleteEmptyDirectories(IEnumerable <string> dir, bool ftp = false) { FTPClient cl = null; string pathOnServer = null; if (ftp) { cl = GetFTPClient(); pathOnServer = Config.PathOnServer; } foreach (var d in dir) { if (ftp) { string url = Utils.CombineUrl(pathOnServer, BundleFolder, d); var hasFiles = cl.GetFilesList(url).Any(); if (!hasFiles) { Out.WriteLine("Deleting folder " + d); cl.DeleteDirectory(url); } } else { if (!Directory.GetFiles(d).Any()) { Out.WriteLine("Deleting folder " + Path.GetFileName(d)); Directory.Delete(d); } } } }