1、判断文件夹是否存在

Directory.Exists(“文件夹路径”)    返回false表示不存在,true表示存在

2、判断文件是否存在

File.Exists("文件路径")    返回false表示不存在,true表示存在

3、创建文件夹

DirectoryInfo dir=new DirectoryInfo("文件夹路径");

dir.Create();

4、创建文件

Fire.Create("文件路径");

 

            //如果文件夹不存在就创建文件夹
            string spath=@"D:\下载文件";
            if(Directory.Exists(spath)==false)
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(spath);
                directoryInfo.Create();
            }
            string filepath=@"D:\下载文件\test.xml";
            if (File.Exists(filepath) == false)
            {
                File.Create(@"D:\下载文件\test.xml");
            }

 

相关文章:

  • 2021-10-23
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-08-16
  • 2021-12-20
相关资源
相似解决方案