判断文件夹是否有了,没有则创建文件夹

来源:互联网 发布:baby在韩国知乎 编辑:程序博客网 时间:2024/05/16 07:42

、判断文件或文件夹是否存在
使用System.IO.File,要检查一个文件是否存在非常简单:
bool exist = System.IO.File.Exists(fileName);

如果需要判断目录(文件夹)是否存在,可以使用System.IO.Directory:
bool exist = System.IO.Directory.Exists(folderName); 

 

__________________________________________________________

string path = @"E:/wwwroot/Vista/Project/Photo";

                        if(Directory.Exists(path))
                        
{
                            upmessage.Text 
="已经有了  " + path;
                            
return;
                        }

                        Directory.CreateDirectory(path);