Saturday, February 13, 2010

HOw to delete all the files and folders from the directory

public object delDirectory(string dirPath)
{

if (!(Directory.Exists(dirPath)))
{
return false;
}
string[] fileEntries = Directory.GetFiles(dirPath);
foreach (string fileName in fileEntries)
{
File.Delete(fileName);
}
string[] subdirectoryEntries = Directory.GetDirectories(dirPath);
foreach (string subdirectory in subdirectoryEntries)
{
delDirectory(subdirectory);
}
Directory.Delete(dirPath);
return true;
}

No comments:

Post a Comment