1 #region 僵尸文件夹中的文件如果不在活文件列表中,删之 2 List<string> deadfile = new List<string>(); 3 foreach(string str in lstZombileDic) 4 { 5 if(Directory.Exists(str)) 6 { 7 var myfiles = Directory.GetFiles(str, "*.*"); 8 foreach (var file in myfiles) 9 { 10 if (imgurl.Contains(file)) 11 { 12 break; 13 } 14 else 15 { 16 if (File.Exists(file)) 17 { 18 deadfile.Add(file); 19 File.Delete(file); 20 sum++; 21 } 22 } 23 } 24 } 25 } 26 #endregion 27 28 #region 下面的图片即将删除 29 //测试时打印出检查 30 if (!Directory.Exists(constant.TestZombileDir)) 31 Directory.CreateDirectory(constant.TestZombileDir); 32 string filePath = constant.TestZombileDir + DateTime.Now.ToString("MM月dd日HH时mm分ss秒") + "Zombile.txt"; 33 using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write)) 34 { 35 StreamWriter sw = new StreamWriter(fs); 36 int i = 1,j=1,k=1; 37 foreach (string url in imgurl) 38 { 39 sw.WriteLine("序号" + i + ":活的图片绝对路径:" + url); 40 i++; 41 } 42 foreach (string str in lstZombileDic) 43 { 44 sw.WriteLine("序号" + j + ":僵尸文件夹:" + str); 45 j++; 46 } 47 foreach (string zombile in deadfile) 48 { 49 sw.WriteLine("序号" + k + ":删除的僵尸图片绝对路径:" + zombile); 50 k++; 51 } 52 sw.Close(); 53 } 54 //the End 55 #endregion