首页 >php教程 >php手册 >C# 对文件操作自我总结

C# 对文件操作自我总结

WBOY
WBOY原创
2016-06-06 20:01:091413浏览

if (System.IO.Directory.Exists(Server.MapPath(System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + System.DateTime.Now.Day.ToString())) == false) //判断文件夹是否存在 { System.IO.Directory.CreateDirector

 if (System.IO.Directory.Exists(Server.MapPath(System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + System.DateTime.Now.Day.ToString())) == false)  //判断文件夹是否存在
 {
     System.IO.Directory.CreateDirectory(Server.MapPath(System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + System.DateTime.Now.Day.ToString()));  //创建文件夹
 }
 System.IO.Directory.Delete(Server.MapPath(System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + System.DateTime.Now.Day.ToString()), true);  //删除文件夹

 

 

 if (System.IO.File.Exists(Server.MapPath(System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + System.DateTime.Now.Day.ToString() + "/chenes.txt")))
 {//存在文件
     System.IO.File.Delete(Server.MapPath(System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + System.DateTime.Now.Day.ToString() + "/chenes.txt"));
 }
 else
 {
     //不存在文件
     System.IO.File.CreateText(Server.MapPath(System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() + "-" + System.DateTime.Now.Day.ToString() + "/chenes.txt"));//创建该文件
 }

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn