//LDH, 2016.12.13 Inspection ScreenShot 삭제 private void DeleteScreenShot(bool _DeleteAll) { string ScreenShotpath; ScreenShotpath = SqliteManager.SqlGetScreenshotPath(); if (ScreenShotpath == null) { MessageBox.Show(new Form { TopMost = true }, "History File is not found."); return; } char Character = '\\'; string[] SplitFolderName = ScreenShotpath.Split(Character); int FolderLength = SplitFolderName.Length; string RemoveFolderPath = ""; string DeleteFolder; int YearIndex = 0; for (int iLoopCount = 0; iLoopCount < 5; iLoopCount++) { //폴더 경로내에 최근 5년 까지의 폴더이름이 있는지 체크 YearIndex = Array.IndexOf(SplitFolderName, (DateTime.Now.Year - iLoopCount).ToString()); if (YearIndex != -1) { break; } } //TrimForm 부터 아래 코드로 변경 //RemoveFolderPath = String.Format(@"\{0}\{1}\{2}\{3}", SplitFolderName[FolderLength - 4], SplitFolderName[FolderLength - 3], SplitFolderName[FolderLength - 2], SplitFolderName[FolderLength - 1]); for (int jLoopCount = YearIndex; jLoopCount < SplitFolderName.Length; jLoopCount++) { RemoveFolderPath = RemoveFolderPath + "\\" + SplitFolderName[jLoopCount]; } ScreenShotpath = ScreenShotpath.Replace(RemoveFolderPath, ""); //Year 폴더 삭제 DirectoryInfo DeleteYearFolderInfo = new DirectoryInfo(ScreenShotpath); if (DeleteYearFolderInfo.Exists) { DirectoryInfo[] YearFolderInfo = DeleteYearFolderInfo.GetDirectories(); foreach (DirectoryInfo YearFolder in YearFolderInfo) { if (_DeleteAll) { if (Convert.ToInt32(YearFolder.Name) <= Convert.ToInt32(DateTime.Now.Year)) { DeleteFolder = String.Format("{0}\\{1}", ScreenShotpath, YearFolder.Name); Directory.Delete(DeleteFolder, true); } } else { if (Convert.ToInt32(YearFolder.Name) < Convert.ToInt32(SplitFolderName[YearIndex])) { DeleteFolder = String.Format("{0}\\{1}", ScreenShotpath, YearFolder.Name); Directory.Delete(DeleteFolder, true); } } } DeleteYearFolderInfo.Refresh(); } //Month 폴더 삭제 ScreenShotpath = String.Format("{0}\\{1}", ScreenShotpath, SplitFolderName[YearIndex]); DirectoryInfo DeleteMonthFolderInfo = new DirectoryInfo(ScreenShotpath); if (DeleteMonthFolderInfo.Exists) { DirectoryInfo[] MonthFolderInfo = DeleteMonthFolderInfo.GetDirectories(); foreach (DirectoryInfo MonthFolder in MonthFolderInfo) { if (Convert.ToInt32(MonthFolder.Name) < Convert.ToInt32(SplitFolderName[YearIndex + 1])) { DeleteFolder = String.Format("{0}\\{1}", ScreenShotpath, MonthFolder.Name); Directory.Delete(DeleteFolder, true); } } DeleteMonthFolderInfo.Refresh(); } //Day 폴더 삭제 ScreenShotpath = String.Format("{0}\\{1}", ScreenShotpath, SplitFolderName[YearIndex + 1]); DirectoryInfo DeleteDayFolderInfo = new DirectoryInfo(ScreenShotpath); if (DeleteDayFolderInfo.Exists) { DirectoryInfo[] DayFolderInfo = DeleteDayFolderInfo.GetDirectories(); foreach (DirectoryInfo DayFolder in DayFolderInfo) { if (Convert.ToInt32(DayFolder.Name) < Convert.ToInt32(SplitFolderName[YearIndex + 2])) { DeleteFolder = String.Format("{0}\\{1}", ScreenShotpath, DayFolder.Name); Directory.Delete(DeleteFolder, true); } } DeleteDayFolderInfo.Refresh(); } }
//LDH, 2016.12.13 Inspection ScreenShot 삭제 private void DeleteScreenShot() { string ScreenShotpath; ScreenShotpath = SqliteManager.SqlGetScreenshotPath(); if (ScreenShotpath == null) { MessageBox.Show(new Form { TopMost = true }, "History File is not found."); return; } char Character = '\\'; string[] SplitFolderName = ScreenShotpath.Split(Character); int FolderLength = SplitFolderName.Length; string RemoveFolderPath; string DeleteFolder; RemoveFolderPath = String.Format(@"\{0}\{1}\{2}\{3}", SplitFolderName[FolderLength - 4], SplitFolderName[FolderLength - 3], SplitFolderName[FolderLength - 2], SplitFolderName[FolderLength - 1]); ScreenShotpath = ScreenShotpath.Replace(RemoveFolderPath, ""); //Year 폴더 삭제 DirectoryInfo DeleteYearFolderInfo = new DirectoryInfo(ScreenShotpath); if (DeleteYearFolderInfo.Exists) { DirectoryInfo[] YearFolderInfo = DeleteYearFolderInfo.GetDirectories(); foreach (DirectoryInfo YearFolder in YearFolderInfo) { if (Convert.ToInt32(YearFolder.Name) < Convert.ToInt32(SplitFolderName[FolderLength - 4])) { DeleteFolder = String.Format("{0}\\{1}", ScreenShotpath, YearFolder.Name); Directory.Delete(DeleteFolder, true); } } } //Month 폴더 삭제 ScreenShotpath = String.Format("{0}\\{1}", ScreenShotpath, SplitFolderName[FolderLength - 4]); DirectoryInfo DeleteMonthFolderInfo = new DirectoryInfo(ScreenShotpath); if (DeleteMonthFolderInfo.Exists) { DirectoryInfo[] MonthFolderInfo = DeleteMonthFolderInfo.GetDirectories(); foreach (DirectoryInfo MonthFolder in MonthFolderInfo) { if (Convert.ToInt32(MonthFolder.Name) < Convert.ToInt32(SplitFolderName[FolderLength - 3])) { DeleteFolder = String.Format("{0}\\{1}", ScreenShotpath, MonthFolder.Name); Directory.Delete(DeleteFolder, true); } } } //Day 폴더 삭제 ScreenShotpath = String.Format("{0}\\{1}", ScreenShotpath, SplitFolderName[FolderLength - 2]); DirectoryInfo DeleteDayFolderInfo = new DirectoryInfo(ScreenShotpath); if (DeleteDayFolderInfo.Exists) { DirectoryInfo[] DayFolderInfo = DeleteDayFolderInfo.GetDirectories(); foreach (DirectoryInfo DayFolder in DayFolderInfo) { if (Convert.ToInt32(DayFolder.Name) < Convert.ToInt32(SplitFolderName[FolderLength - 1])) { DeleteFolder = String.Format("{0}\\{1}", ScreenShotpath, DayFolder.Name); Directory.Delete(DeleteFolder, true); } } } }