Create directory, check files and RecycleOption
This commit is contained in:
@ -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)";
|
||||
|
@ -10,16 +10,24 @@ public class AppSettings
|
||||
public string CompareRootDirectory { init; get; }
|
||||
public int MaxDegreeOfParallelism { init; get; }
|
||||
public string OutputExtension { init; get; }
|
||||
public bool RecycleOption { init; get; }
|
||||
public string SearchPattern { init; get; }
|
||||
public string WorkingDirectoryName { init; get; }
|
||||
|
||||
[JsonConstructor]
|
||||
public AppSettings(string company, string compareRootDirectory, int maxDegreeOfParallelism, string outputExtension, string searchPattern, string workingDirectoryName)
|
||||
public AppSettings(string company,
|
||||
string compareRootDirectory,
|
||||
int maxDegreeOfParallelism,
|
||||
string outputExtension,
|
||||
bool recycleOption,
|
||||
string searchPattern,
|
||||
string workingDirectoryName)
|
||||
{
|
||||
Company = company;
|
||||
CompareRootDirectory = compareRootDirectory;
|
||||
MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
OutputExtension = outputExtension;
|
||||
RecycleOption = recycleOption;
|
||||
SearchPattern = searchPattern;
|
||||
WorkingDirectoryName = workingDirectoryName;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ public class AppSettings
|
||||
public string CompareRootDirectory { get; set; }
|
||||
public int? MaxDegreeOfParallelism { get; set; }
|
||||
public string OutputExtension { get; set; }
|
||||
public bool? RecycleOption { get; set; }
|
||||
public string SearchPattern { get; set; }
|
||||
public string WorkingDirectoryName { get; set; }
|
||||
|
||||
@ -28,11 +29,14 @@ public class AppSettings
|
||||
Models.AppSettings result;
|
||||
if (appSettings?.MaxDegreeOfParallelism is null)
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
if (appSettings?.RecycleOption is null)
|
||||
throw new NullReferenceException(nameof(appSettings.RecycleOption));
|
||||
result = new(
|
||||
appSettings.Company,
|
||||
appSettings.CompareRootDirectory,
|
||||
appSettings.MaxDegreeOfParallelism.Value,
|
||||
appSettings.OutputExtension,
|
||||
appSettings.RecycleOption.Value,
|
||||
appSettings.SearchPattern,
|
||||
appSettings.WorkingDirectoryName
|
||||
);
|
||||
|
@ -6,6 +6,7 @@
|
||||
}
|
||||
},
|
||||
"MaxDegreeOfParallelism": 6,
|
||||
"RecycleOption": true,
|
||||
"SearchPattern": "*.*",
|
||||
"Serilog": {
|
||||
"MinimumLevel": "Debug"
|
||||
|
@ -11,6 +11,7 @@
|
||||
}
|
||||
},
|
||||
"MaxDegreeOfParallelism": 6,
|
||||
"RecycleOption": false,
|
||||
"SearchPattern": "*.jpg",
|
||||
"Serilog": {
|
||||
"Using": [
|
||||
|
Reference in New Issue
Block a user