版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BYH371256/article/details/85263816
本章讲述:C#判断指定目录是否存在,判断文件是否存在,不存在则创建
1、判断文件夹是否存在
//spath:文件夹路径名
using System.IO;
if (Directory.Exists(spath))
{
}
else
{
DirectoryInfo directoryInfo = new DirectoryInfo(spath);
directoryInfo.Create();
}
2、判断文件是否存在
// filePath 文件路径名
if (!File.Exists(filePath))
{
//MessageBox.Show(filePath + " not exists!");
FileStream fs = File.Create(filePath);//创建文件
fs.Close();
return ;
}
else
{
MessageBox.Show(filePath + " exists!");
//执行读写操作
}