菜鸟今天终于搞清楚了文件夹与文件的判断,创建,删除

Directory.CreateDirectory()此方法不仅能建文件夹,而且还能建目录。。

 

 

private string path = @"D:\file\a\";

private void folderExist()

if (Directory.Exists(path) == true)
{
Directory.Delete (path);
MessageBox.Show("文件夹已经删除");
}
else
{
Directory.CreateDirectory(path);
MessageBox.Show("文件夹已经创建");
}; 
}

private void fileExist() {
if (System.IO.File.Exists(path + "\a.txt"))
{
System.IO.File.Delete(path +"*.tx");
MessageBox.Show("文件已经删除");
}
else {
System.IO.File.Create(path + "a.txt");
MessageBox.Show("文件已经创建");
}
}

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2021-09-20
  • 2021-12-21
  • 2021-12-03
  • 2021-12-21
  • 2021-11-24
猜你喜欢
  • 2022-01-10
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案