Here is how to use it:
DeleteSubFolders(@"c:\svn\MyProject\Trunk",".svn",true);
Here is the code:
public static void DeleteSubFolders(string folderPath, string wildcardPattern, bool top)
{String[] list;
//If we are at the top level, get all directory names that match the pattern
if (top)list = Directory.GetDirectories(folderPath, wildcardPattern, SearchOption.AllDirectories);
else //Get directories and files for matching sub directorieslist = Directory.GetFileSystemEntries(folderPath, wildcardPattern);
foreach (string item in list)
{//Sub directories
if (Directory.Exists(item)){
//Match all sub directoriesDeleteSubFolders(item, "*", false);
}else // Files in directory
{//Get the attribute for the file
FileAttributes fileAtts = File.GetAttributes(item);//If it is read only make it writable
if ((fileAtts & FileAttributes.ReadOnly) != 0)
{File.SetAttributes(item, fileAtts & ~FileAttributes.ReadOnly);
}File.Delete(item);
}
}//Delete the matching folder that we are in
if (top == false)
{Directory.Delete(folderPath);
}}
