using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO; namespace ReligionServer.util { public class FileUtil { /// <summary> /// 根据给定路径删除文件; 如果给定路径下只有一个文件, 且要删除这个文件, 那么就将目录一起删除 /// </summary> /// <param name="path"></param> public static void RemoveFile(String path) { if (File.Exists(path)) { File.Delete(path); DirectoryInfo directory = new FileInfo(path).Directory; if (directory.GetFiles().Length == 0) { directory.Delete(); } } } } }