文件夹和文件的创建

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

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

private string path = @"D:filea";

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("文件已经创建");
}
}

原文地址:https://www.cnblogs.com/jiningning/p/4708116.html