public static bool Delete(string path) { if (path == null) { return(false); } string dirRoot = Path.GetDirectoryName(path); string pattern = Path.GetFileName(path); // directory if (IsDirectory(path)) { DirectoryHelper.CleanUp(path); return(true); } // wild-card char if (path.IndexOf("*", StringComparison.Ordinal) >= 0) { if (pattern != null && dirRoot != null) { string[] fileList = Directory.GetFileSystemEntries(dirRoot, pattern, SearchOption.TopDirectoryOnly); foreach (string file in fileList) { if (IsDirectory(file)) { //it's a directory Directory.Delete(file, true); } else { // we can before, we want to avoid deleting an already deleted file in sub-directory File.Delete(file); } } } } else { // single file delete File.Delete(path); } return(true); }
public static bool Delete(string path) { if (path == null) { return(false); } var dirRoot = Path.GetDirectoryName(path); var pattern = Path.GetFileName(path); // directory if (IsDirectory(path)) { DirectoryHelper.CleanUp(path); return(true); } // wild-card char if (path.IndexOf("*", StringComparison.Ordinal) >= 0) { if (dirRoot != null) { var fileList = Directory.GetFileSystemEntries(dirRoot, pattern, SearchOption.TopDirectoryOnly); foreach (string file in fileList) { DeletePath(file); } } } else { // single file delete File.Delete(path); } return(true); }