删除指定目录下的文件夹
1 public async Task Execute(IJobExecutionContext context) 2 { 3 var filePath = _configuration.GetSection("TempFolderPath").GetSection("Path").Value; 4 5 var Folders = Directory.GetDirectories(filePath).Select(o => new 6 { 7 CreatTime = Directory.GetCreationTime(o), 8 url = o 9 }).ToList(); 10 11 var SevenDaysFolders = Folders.Where(d => d.CreatTime < DateTime.Now.AddDays(-7)).ToList(); 12 13 FileAttributes attr = File.GetAttributes(filePath); 14 if (attr == FileAttributes.Directory)//该目录是否是文件夹 15 { 16 foreach (var s in SevenDaysFolders) 17 { 18 Directory.Delete(s.url, true); 19 } 20 } 21 await Task.CompletedTask; 22 }