Search This Blog

February 10, 2010

Delete files and folders recurcively


public void DeleteAllFilesAndFolders(string folderPath)
{
try
{
if (String.IsNullOrEmpty(folderPath))
{
return;
}
foreach (string subDirectory in Directory.GetDirectories(folderPath))
{
foreach (string fileName in Directory.GetFiles(subDirectory))
{
File.Delete(fileName);
}
DeleteAllFilesAndFolders(subDirectory);
}
if (Directory.Exists(folderPath))
{
Directory.Delete(folderPath, true);
}
}
catch
{

}
}

No comments: