People
log pattern
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -76,7 +76,7 @@ internal static class HelperHardcodedFileSearchAndSort
|
||||
}
|
||||
}
|
||||
}
|
||||
log.LogInformation(sourceDirectory);
|
||||
log.LogInformation("{sourceDirectory}", sourceDirectory);
|
||||
}
|
||||
|
||||
}
|
@ -41,7 +41,7 @@ internal static class HelperLogMerge
|
||||
continue;
|
||||
segment1 = segments[1];
|
||||
hour = int.Parse(sourceFileNameWithoutExtension.Substring(8, 2));
|
||||
if (keyValuePairs[day].ContainsKey(hour))
|
||||
if (keyValuePairs[day].TryGetValue(hour, out _))
|
||||
continue;
|
||||
keyValuePairs[day].Add(hour, File.ReadAllLines(sourceFile));
|
||||
moveFiles.Add(sourceFile);
|
||||
|
@ -9,14 +9,14 @@ internal static class HelperRenameToOldMoveDeleteOldMerge
|
||||
{
|
||||
string checkDirectory = argsZero[0..^1];
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
log.LogInformation(string.Concat("<", checkDirectory, "> doesn't exist!"));
|
||||
log.LogInformation("<{checkDirectory}> doesn't exist!", checkDirectory);
|
||||
else
|
||||
{
|
||||
string renameFile;
|
||||
string destinationFile;
|
||||
List<string> deleteFiles = new();
|
||||
string[] moveFiles = Directory.GetFiles(argsZero, "*", SearchOption.TopDirectoryOnly);
|
||||
log.LogInformation(string.Concat("<", moveFiles.Length, "> to move"));
|
||||
log.LogInformation("<{moveFiles.Length}> to move", moveFiles.Length);
|
||||
foreach (string moveFile in moveFiles)
|
||||
{
|
||||
destinationFile = string.Concat(checkDirectory, moveFile[argsZero.Length..]);
|
||||
@ -30,7 +30,7 @@ internal static class HelperRenameToOldMoveDeleteOldMerge
|
||||
deleteFiles.Add(renameFile);
|
||||
}
|
||||
}
|
||||
log.LogInformation(string.Concat("<", deleteFiles.Count, "> to delete"));
|
||||
log.LogInformation("<{deleteFiles.Count}> to delete", deleteFiles.Count);
|
||||
foreach (string deleteFile in deleteFiles)
|
||||
{
|
||||
for (short i = 0; i < short.MaxValue; i++)
|
||||
|
@ -5,30 +5,33 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace File_Folder_Helper.Helpers;
|
||||
|
||||
internal static class HelperZipFilesByDate
|
||||
internal static partial class HelperZipFilesByDate
|
||||
{
|
||||
|
||||
[GeneratedRegex("[a-zA-Z0-9]{1,}")]
|
||||
private static partial Regex LowerAlphaAlphaAndNumber();
|
||||
|
||||
internal static bool ZipFilesByDate(ILogger log, string sourceDirectory, SearchOption searchOption = SearchOption.TopDirectoryOnly, string dayFormat = "")
|
||||
{
|
||||
bool result = false;
|
||||
string key;
|
||||
bool addFile;
|
||||
string? zipPath;
|
||||
string fileName;
|
||||
string? zipPath;
|
||||
FileInfo fileInfo;
|
||||
string weekOfYear;
|
||||
string[] segments;
|
||||
string[] subFiles;
|
||||
string weekOfYear;
|
||||
FileInfo fileInfo;
|
||||
string zipDirectory;
|
||||
DateTime creationTime;
|
||||
string? directoryName;
|
||||
DateTime lastWriteTime;
|
||||
DateTime nowDateTime = DateTime.Now;
|
||||
Regex regex = new("[a-zA-Z0-9]{1,}");
|
||||
DateTime dateTime = DateTime.MinValue;
|
||||
DateTime firstEmail = new(2019, 3, 8);
|
||||
CultureInfo cultureInfo = new("en-US");
|
||||
Calendar calendar = cultureInfo.Calendar;
|
||||
Regex regex = LowerAlphaAlphaAndNumber();
|
||||
Dictionary<string, DateTime> weeks = new();
|
||||
int ticksLength = nowDateTime.AddDays(-6).Ticks.ToString().Length;
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
@ -107,14 +110,12 @@ internal static class HelperZipFilesByDate
|
||||
{
|
||||
key = Path.Combine(zipDirectory, $"{element.Key}.zip");
|
||||
if (File.Exists(key))
|
||||
{
|
||||
for (short i = 101; i < short.MaxValue; i++)
|
||||
{
|
||||
key = Path.Combine(zipDirectory, $"{element.Key}_{i}.zip");
|
||||
if (!File.Exists(key))
|
||||
break;
|
||||
}
|
||||
}
|
||||
using ZipArchive zip = ZipFile.Open(key, ZipArchiveMode.Create);
|
||||
foreach (string file in element.Value)
|
||||
{
|
||||
@ -122,11 +123,9 @@ internal static class HelperZipFilesByDate
|
||||
File.Delete(file);
|
||||
}
|
||||
if (zipPath is not null && Directory.Exists(zipPath) && !string.IsNullOrEmpty(directoryName))
|
||||
{
|
||||
try
|
||||
{ Directory.SetLastWriteTime(directoryName, DateTime.Now); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
subFiles = Directory.GetFiles(zipDirectory, "*.zip", SearchOption.TopDirectoryOnly);
|
||||
foreach (string subFile in subFiles)
|
||||
@ -136,7 +135,6 @@ internal static class HelperZipFilesByDate
|
||||
if (segments.Length > 2)
|
||||
fileName = string.Concat(segments[0], '_', segments[1], '_', segments[2]);
|
||||
if (weeks.TryGetValue(fileName, out DateTime value))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!result)
|
||||
@ -144,14 +142,11 @@ internal static class HelperZipFilesByDate
|
||||
File.SetLastWriteTime(subFile, value);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
if (topDirectory != sourceDirectory)
|
||||
{
|
||||
try
|
||||
{ _ = HelperDeleteEmptyDirectories.DeleteEmptyDirectories(topDirectory); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
log.LogInformation("{topDirectory}", topDirectory);
|
||||
}
|
||||
return result;
|
||||
@ -166,7 +161,6 @@ internal static class HelperZipFilesByDate
|
||||
string? zipDirectory;
|
||||
DateTimeOffset? dateTimeOffset;
|
||||
foreach (string zipFile in zipFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
dateTimeOffset = null;
|
||||
@ -240,7 +234,6 @@ internal static class HelperZipFilesByDate
|
||||
{ File.Move(zipFile, checkFile); }
|
||||
catch (Exception) { log.LogInformation("<{zipFile}> couldn't be moved!", zipFile); }
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user