public static void Delete(IEnumerable<string> paths) { paths.Each(path => { if (path.Contains("*")) All(path).Each(p => Delete(p)); path = Paths.Normalize(path); var ftppath = path.Substring(1); var diskpath = Paths.Map(path); if (Directory.Exists(diskpath)) { if (Paths.IsWritable(path)) { try { Directory.Delete(diskpath, true); } catch { var info = new DirectoryInfo(diskpath); var children = info.EnumerateFileSystemInfos("*", SearchOption.AllDirectories).ToList(); foreach (var file in children.OfType<FileInfo>()) File.Delete(file.FullName); children.Reverse(); foreach (var dir in children.OfType<DirectoryInfo>()) Directory.Delete(dir.FullName); } } else if (CanUseFtp) { using (var ftp = new FtpClient()) { ftp.DeleteDirectoryRecursive(ftppath); ftp.Close(); } } else throw new IOException(string.Format("Path {0} is write protected.", path)); } else if (File.Exists(diskpath)) { if (Paths.IsWritable(path)) File.Delete(diskpath); else if (CanUseFtp) { using (var ftp = new FtpClient()) { string dir, name; ftp.Split(path, out dir, out name); ftp.ChangeDirectory(dir); ftp.DeleteFile(name); ftp.Close(); } } else throw new IOException(string.Format("Path {0} is write protected.", path)); } }); }