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

C# 对文件操作自我总结

WBOY
WBOYOriginal
2016-06-06 20:01:091416browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:弹出窗口 PHPNext article:决定将来的故事