/// <summary> /// Метод, работающий в отдельном потоке при запуске механизма поиска и удаления. /// </summary> private void RW_Wrk_DoWork(object sender, DoWorkEventArgs e) { // Создаём список файлов для удаления... List <string> DeleteQueue = DetectFilesForCleanup(RemDirs); // Формируем счётчики... int TotalFiles = DeleteQueue.Count; int i = 1, j = 0; // Удаляем файлы из очереди очистки... foreach (string Fl in DeleteQueue) { try { j = (int)Math.Round(((double)i / (double)TotalFiles * (double)100.00), 0); i++; if ((j >= 0) && (j <= 100)) { RW_Wrk.ReportProgress(j); } } catch (Exception Ex) { CoreLib.WriteStringToLog(Ex.Message); } try { if (File.Exists(Fl)) { File.SetAttributes(Fl, FileAttributes.Normal); File.Delete(Fl); } } catch (Exception Ex) { CoreLib.WriteStringToLog(Ex.Message); } } // Удаляем пустые каталоги... foreach (string Dir in RemDirs) { FileManager.RemoveEmptyDirectories(Path.GetDirectoryName(Dir)); } }
/// <summary> /// Removes all files and directories recursively from specified directories. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Additional arguments.</param> private void RW_Wrk_DoWork(object sender, DoWorkEventArgs e) { // Parsing arguments list... List <String> Arguments = e.Argument as List <String>; // Searching for candidates... List <string> DeleteQueue = DetectFilesForCleanup(Arguments); // Creating some counters... int TotalFiles = DeleteQueue.Count; int CurrentFile = 1, CurrentPercent; // Removing all files from list... foreach (string Fl in DeleteQueue) { try { // Removing file if exists... if (File.Exists(Fl)) { File.SetAttributes(Fl, FileAttributes.Normal); File.Delete(Fl); } // Reporting progress to form... CurrentPercent = (int)Math.Round(CurrentFile / (double)TotalFiles * 100.00d, 0); CurrentFile++; if ((CurrentPercent >= 0) && (CurrentPercent <= 100)) { RW_Wrk.ReportProgress(CurrentPercent); } } catch (Exception Ex) { Logger.Warn(Ex); } } // Removing empty directories after files removal... foreach (string Dir in Arguments) { try { FileManager.RemoveEmptyDirectories(Path.GetDirectoryName(Dir)); } catch (Exception Ex) { Logger.Error(Ex, DebugStrings.AppDbgExClnEmptyDirs); } } }