フォルダーとそのフォルダー内のすべてのファイルとフォルダーを削除しようとしています。以下のコードを使用していますが、エラーが表示Folder is not empty
されます。どうすればよいですか?
try
{
var dir = new DirectoryInfo(@FolderPath);
dir.Attributes = dir.Attributes & ~FileAttributes.ReadOnly;
dir.Delete();
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[i].Index);
}
catch (IOException ex)
{
MessageBox.Show(ex.Message);
}