Create directory, check files and RecycleOption

This commit is contained in:
2023-01-12 21:48:39 -07:00
parent fbaafe0137
commit c5986b5cba
11 changed files with 72 additions and 12 deletions

View File

@ -61,9 +61,11 @@ public class DeleteByDistinct
fileInfo = new(file);
if (fileInfo.Length < 100)
continue;
checkLength = fileInfo.Length;
if (appSettings.RecycleOption)
checkLength = 1;
else
checkLength = fileInfo.Length;
// checkLength = (long)Math.Round((double)(fileInfo.Length / 1000));
// checkLength = 1;
if (!fileSizeToCollection.TryGetValue(checkLength, out fileTicksToNames))
{
fileSizeToCollection.Add(checkLength, new());
@ -76,9 +78,11 @@ public class DeleteByDistinct
// if (!fileTicksToNames.TryGetValue(fileInfo.LastWriteTime.Ticks, out fileNames))
// throw new Exception();
// }
checkTicks = new DateTime(ticks).Ticks;
if (appSettings.RecycleOption)
checkTicks = 1;
else
checkTicks = new DateTime(ticks).Ticks;
// checkTicks = new DateTime(fileInfo.LastWriteTime.Year, fileInfo.LastWriteTime.Month, fileInfo.LastWriteTime.Day).Ticks;
// checkTicks = 1;
if (!fileTicksToNames.TryGetValue(checkTicks, out fileNames))
{
fileTicksToNames.Add(checkTicks, new());
@ -113,9 +117,18 @@ public class DeleteByDistinct
{
foreach (string file in deletedFiles)
{
try
{ File.Delete(file); }
catch (Exception) { }
if (!appSettings.RecycleOption)
{
try
{ File.Delete(file); }
catch (Exception) { }
}
else
{
try
{ Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(file, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin); }
catch (Exception) { }
}
}
totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
message = $") Looking for empty directories from <{directory}> - {totalSeconds} total second(s)";