string path ="";
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
if(folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
path = folderBrowserDialog.SelectedPath;
}
if(path != "")
{
if(Directory.GetDirectories(path).Length != )
{
foreach(string folder in Directory.GetDirectories(path))
{
foreach(string file in Directory.GetFiles(folder))
{
}
}
}
else
{
foreach(string file in Directory.GetFiles(path))
{
}
}
}
foreach(string folder in Directory.GetDirectories(path))
{
if (Directory.Exists(filePath))
{
Directory.Delete(filePath, true);
}
}
或
DirectoryInfo dir = new DirectoryInfo(path);
if (dir.Exists)
{
DirectoryInfo[] childs = dir.GetDirectories();
foreach (DirectoryInfo child in childs)
{
child.Delete(true);
}
dir.Delete(true);
}