1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public void DeleteFiles(string path) { try { string[] files = Directory.GetFiles(path); List<string> picFiles = new List<string>(); foreach (string f in files) { string fileName = Path.GetFileName(f); if (fileName.ToUpper().Contains("LW")) picFiles.Add(f); } picFiles.ForEach((f) => { FileInfo fi = new FileInfo(f); DateTime dtWrite = fi.LastWriteTime; if ((DateTime.Now - dtWrite).Days > deleteDays) fi.Delete(); }); } catch (System.Exception ex) { } }
|