Maison  >  Article  >  php教程  >  C# 对文件操作自我总结

C# 对文件操作自我总结

WBOY
WBOYoriginal
2016-06-06 20:01:091360parcourir

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"));//创建该文件
 }

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:弹出窗口 PHPArticle suivant:决定将来的故事