private void button1_Click(object sender, EventArgs e)
{
folderBrowserDialog1.SelectedPath = @"C:\My Projects\temp\DirectoryControl\Test";
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
private void button2_Click(object sender, EventArgs e)
{
if (Directory.Exists(textBox1.Text))
{
DirectoryInfo di = new DirectoryInfo(textBox1.Text);
DeleteAllFilesInDirectories(di);
Directory.Delete(textBox1.Text, true);
}
else
{
MessageBox.Show("Invalid path!");
}
}
private void DeleteAllFilesInDirectories(DirectoryInfo di)
{
FileInfo[] fi = null;
DirectoryInfo[] subDir = null;
fi = di.GetFiles();
if (fi != null)
{
foreach (FileInfo aFi in fi)
{
//delete all
aFi.Attributes = FileAttributes.Normal;
aFi.Delete();
}
subDir = di.GetDirectories();
foreach (DirectoryInfo adi in subDir )
{
DeleteAllFilesInDirectories(adi);
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment