1.判断文件夹是否存在
string path="C:\\";
if (System.IO.Directory.Exists(path))
{
//存在
}
else
{
DirectoryInfo directoryInfo = new DirectoryInfo(path);
directoryInfo.Create();
}
2.判断文件是否存在
// filePath 文件路径名
string filePath = "C:\\A.txt";
if (!File.Exists(filePath))
{
//MessageBox.Show(filePath + " not exists!");
FileStream fs = File.Create(filePath);//创建文件
fs.Close();
return ;
}
else
{
MessageBox.Show(filePath + " exists!");
//执行读写操作
}