public void ExecuteDeleteCommand(Model_ThingsToDelete ttd, BackgroundWorker bgWorker, Queue<Model_ThingsToDelete> TTD, bool preview = false)
{
if (preview)
{
FileInfo fi = new FileInfo(ttd.FullPathName);
if (fi.Exists)
{
string text = string.Format("{0} {1} {2}", "Delete", Win32API.FormatByteSize(fi.Length), ttd.FullPathName);
UpdateProgressLog(text, text);
}
}
else
{
// next we need to know if the file exists so we can delete it.
FileInfo fi = new FileInfo(ttd.FullPathName);
if (fi.Exists)
{
long FileSize = 0;
try
{
string text = string.Format("{0} {1} {2}", "Delete", Win32API.FormatByteSize(fi.Length),
ttd.FullPathName);
// then report to the gui
bgWorker.ReportProgress(-1, text);
// then we delete it.
if (fi.Exists)
FileSize = fi.Length;
FileOperations.Delete(fi.FullName);
text = string.Format(" - DELETED");
//// then report to the gui
bgWorker.ReportProgress(-1, text);
Worker.I.TotalFileSize += FileSize;
Worker.I.TotalFileDelete++;
}
catch (Exception ex)
{
Worker.I.TotalFileSkipped++;
Worker.I.TotalSkippedFileSize += FileSize;
var text =
"-ERROR while deleting a above file please close application which may lock this file " +
ex.Message;
bgWorker.ReportProgress(-1, text);
}
}
// delete directories as well if search parameter is walk.all
if (ttd.search == SEARCH.walk_all)
{
if (TTD.Count == 0)
{
DirectoryInfo di = new DirectoryInfo(ttd.path);
if (di.Exists)
{
FileOperations.I.DeleteEmptyDirectories(ttd.path, (a) =>
{
//string text = string.Format("Delete 0 {0} - DELETED", a);
string text = string.Format("Delete 0 {0}", a);
// then report to the gui
bgWorker.ReportProgress(-1, text);
});
}
}
}
}
}