文件夹和文件的创建

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

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

posted @ 2015-08-06 15:31  快乐的小太阳  阅读(151)  评论(0编辑  收藏  举报