导入excle到服务器时候删除服务器历史数据
作者:互联网
//删除历史数据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); } }
标签:folders,dInfo,Directory,导入,foreach,file,var,服务器,excle 来源: https://www.cnblogs.com/lvqianqian/p/11082173.html