Created
January 9, 2020 10:01
-
-
Save SamKr/f307b87949eabca150dbf56448b643e2 to your computer and use it in GitHub Desktop.
Delete all files in folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void DeleteAllFilesInFolder(string path) | |
{ | |
try | |
{ | |
if (!Directory.Exists(path)) return; | |
var di = new DirectoryInfo(path); | |
foreach (var file in di.GetFiles()) | |
{ | |
try | |
{ | |
File.SetAttributes(file.FullName, FileAttributes.Normal); | |
File.Delete(file.FullName); | |
count++; | |
} | |
catch (Exception ex) | |
{ | |
throw; | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
throw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment