//删除历史数据EXCLE 当天前一天的数据都删除 var folder = Path.GetDirectoryName(absFilePath); var files = Directory.GetFiles(folder); foreach (var file in files) { if (File.GetCreationTime(file) <= DateTime.Now.AddDays(-1)) { File.Delete(file); } } //删除历史数据 删除文件夹,当天以前的文件夹都删除 var tempFolder = HttpContext.Current.Server.MapPath("/Upload/TMS/WayBill"); ---服务器的虚拟地址
//var tempFolder = AppDomain.CurrentDomain.BaseDirectory + "Upload\\Import\\WayBillOther"; ---------本地的时候可以用 var folders = Directory.GetDirectories(tempFolder); foreach (var folderPath in folders) { DirectoryInfo dInfo = new DirectoryInfo(folderPath); if (dInfo.CreationTime < DateTime.Now.AddDays(-1)) { Directory.Delete(dInfo.FullName, true); } }