【发布时间】:2013-10-06 04:00:44
【问题描述】:
我创建了一个按钮。在按钮的事件处理程序中,我想删除文件夹(abc)中的所有文件。
下面是代码:
private void button1_Click_1(object sender, EventArgs e)
{
MessageBox.Show("Are you sure!!!! The files in the folder will be deleted permanently");
this.Close();
string[] filePaths = Directory.GetFiles(@"C:\abc\");
foreach (string filePath in filePaths)
File.Delete(filePath);
}
例如,文件夹中有一个 Word 文件,如果打开它,我会收到一条错误消息:
进程无法访问文件'C:\abc\New Microsoft Word Document.docx',因为它正被另一个进程使用。
【问题讨论】:
-
stackoverflow.com/questions/317071/…有样本可以找到持有锁的进程。
-
@gp。这是原始线程:stackoverflow.com/questions/876473/…