Skip to content

Instantly share code, notes, and snippets.

@SamKr
Created January 9, 2020 10:01
Show Gist options
  • Save SamKr/f307b87949eabca150dbf56448b643e2 to your computer and use it in GitHub Desktop.
Save SamKr/f307b87949eabca150dbf56448b643e2 to your computer and use it in GitHub Desktop.
Delete all files in folder
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