Add option directory

Allow lower case drive letters
This commit is contained in:
Mike Phares 2025-02-11 14:23:11 -07:00
parent 264b6319cb
commit b771761936
3 changed files with 59 additions and 51 deletions

21
.vscode/launch.json vendored
View File

@ -13,25 +13,8 @@
"args": [ "args": [
"s", "s",
"X", "X",
"D:/5-Other-Small/Proxmox/ffnm", "D:/5-Other-Small/Kanban-mestsa003/{}/2025/2025_Week_05/223065",
"Day-Helper-2025-01-26", "Day-Helper-2025-02-04",
"*.txt",
"MM/dd/yy",
"Statement Period",
"WOODS,JASON P",
"666",
"777",
"888",
"999",
"s",
"P",
"D:/5-Other-Small/Proxmox/ffnm",
"-d",
"L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode",
"-k",
"Mike",
"-p",
"S"
], ],
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"console": "integratedTerminal", "console": "integratedTerminal",

View File

@ -1,7 +1,9 @@
using File_Folder_Helper.Helpers; using File_Folder_Helper.Helpers;
using File_Folder_Helper.Models; using File_Folder_Helper.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@ -24,7 +26,7 @@ internal static partial class Helper20240623
private record Input(long? AfterEpochTotalMilliseconds, private record Input(long? AfterEpochTotalMilliseconds,
string CodeInsiders, string CodeInsiders,
string? DestinationDirectory, ReadOnlyCollection<string> DestinationDirectories,
string DirectoryFilter, string DirectoryFilter,
string Done, string Done,
string IndexFile, string IndexFile,
@ -379,10 +381,19 @@ internal static partial class Helper20240623
string subTasks = args[3].Replace('_', ' '); string subTasks = args[3].Replace('_', ' ');
string codeInsiders = args[4].Replace('_', ' '); string codeInsiders = args[4].Replace('_', ' ');
string sourceDirectory = Path.GetFullPath(args[0]); string sourceDirectory = Path.GetFullPath(args[0]);
string? destinationDirectory = args.Count < 8 ? null : Path.GetFullPath(args[9]); string[] tasks = args[6].Split(',').Select(l => l.Replace('_', ' ')).ToArray();
long? afterEpochTotalMilliseconds = args.Count < 9 ? null : long.Parse(args[10]); long? afterEpochTotalMilliseconds = args.Count < 11 ? null : long.Parse(args[10]);
ReadOnlyCollection<string> tasks = args[6].Split(',').Select(l => l.Replace('_', ' ')).ToArray().AsReadOnly(); string[] destinationDirectories = args.Count < 10 ? [] : args.Count < 12 ? [Path.GetFullPath(args[9])] : [Path.GetFullPath(args[9]), Path.GetFullPath(args[11])];
Input input = new(afterEpochTotalMilliseconds, codeInsiders, destinationDirectory, directoryFilter, done, indexFile, searchPattern, subTasks, sourceDirectory, tasks); Input input = new(AfterEpochTotalMilliseconds: afterEpochTotalMilliseconds,
CodeInsiders: codeInsiders,
DestinationDirectories: destinationDirectories.AsReadOnly(),
DirectoryFilter: directoryFilter,
Done: done,
IndexFile: indexFile,
SearchPattern: searchPattern,
SubTasks: subTasks,
SourceDirectory: sourceDirectory,
Tasks: tasks.AsReadOnly());
if (input.Tasks[0] != "- [" || input.Tasks[1] != "](") if (input.Tasks[0] != "- [" || input.Tasks[1] != "](")
throw new Exception(JsonSerializer.Serialize(input, InputSourceGenerationContext.Default.Input)); throw new Exception(JsonSerializer.Serialize(input, InputSourceGenerationContext.Default.Input));
return input; return input;
@ -391,7 +402,11 @@ internal static partial class Helper20240623
private static string? MaybeWriteAndGetIndexFile(Input input, Record record, string? checkDirectory) private static string? MaybeWriteAndGetIndexFile(Input input, Record record, string? checkDirectory)
{ {
string? result; string? result;
if (string.IsNullOrEmpty(checkDirectory) || input.AfterEpochTotalMilliseconds is null || string.IsNullOrEmpty(input.DestinationDirectory) || !checkDirectory.Contains(input.DestinationDirectory)) if (string.IsNullOrEmpty(checkDirectory) || input.AfterEpochTotalMilliseconds is null || input.DestinationDirectories.Count == 0)
result = null;
else
{
if (!input.DestinationDirectories.Any(checkDirectory.Contains))
result = null; result = null;
else else
{ {
@ -423,6 +438,7 @@ internal static partial class Helper20240623
} }
} }
} }
}
return result; return result;
} }
@ -478,15 +494,16 @@ internal static partial class Helper20240623
return result; return result;
} }
private static FileInfo GetIndexFileInfo(Input input, Record record, string codeInsidersLine) private static FileInfo GetIndexFileInfo(ILogger<Worker> logger, Input input, Record record, string codeInsidersLine)
{ {
FileInfo result; FileInfo result;
string? indexFile; string? indexFile;
List<string> results; List<string> results;
string? checkDirectory = codeInsidersLine[input.CodeInsiders.Length..^1]; string raw = codeInsidersLine[input.CodeInsiders.Length..^1];
string checkDirectory = $"{raw[..2].ToUpper()}{raw[2..]}";
if (!Directory.Exists(checkDirectory)) if (!Directory.Exists(checkDirectory))
{ {
if (!string.IsNullOrEmpty(input.DestinationDirectory) && checkDirectory.Contains(input.DestinationDirectory)) if (input.DestinationDirectories.Count > 0 && input.DestinationDirectories.Any(checkDirectory.Contains))
_ = Directory.CreateDirectory(checkDirectory); _ = Directory.CreateDirectory(checkDirectory);
} }
if (!Directory.Exists(checkDirectory)) if (!Directory.Exists(checkDirectory))
@ -507,6 +524,8 @@ internal static partial class Helper20240623
indexFile = MaybeWriteAndGetIndexFile(input, record, checkDirectory); indexFile = MaybeWriteAndGetIndexFile(input, record, checkDirectory);
if (!string.IsNullOrEmpty(indexFile)) if (!string.IsNullOrEmpty(indexFile))
results.Add(indexFile); results.Add(indexFile);
else
logger.LogInformation("<{checkDirectory}>", checkDirectory);
} }
} }
result = results.Count == 0 ? new(Path.Combine(checkDirectory, input.IndexFile)) : new(results[0]); result = results.Count == 0 ? new(Path.Combine(checkDirectory, input.IndexFile)) : new(results[0]);
@ -549,7 +568,7 @@ internal static partial class Helper20240623
if (record.StopLine is null) if (record.StopLine is null)
continue; continue;
codeInsidersLine = record.LineNumber.Lines[record.CodeInsidersLine.Value]; codeInsidersLine = record.LineNumber.Lines[record.CodeInsidersLine.Value];
fileInfo = GetIndexFileInfo(input, record, codeInsidersLine); fileInfo = GetIndexFileInfo(logger, input, record, codeInsidersLine);
if (!fileInfo.Exists) if (!fileInfo.Exists)
{ {
checkDirectory = codeInsidersLine[input.CodeInsiders.Length..^1]; checkDirectory = codeInsidersLine[input.CodeInsiders.Length..^1];

View File

@ -16,13 +16,16 @@
// console.log("dateText: " + dateText); // console.log("dateText: " + dateText);
// DateTime utcMeDateTime = new(1980, 1, 17, 0, 0, 0, DateTimeKind.Utc); // DateTime utcMeDateTime = new(1980, 1, 17, 0, 0, 0, DateTimeKind.Utc);
// long meTotalSeconds = (long)Math.Floor(fileInfo.LastWriteTime.ToUniversalTime().Subtract(utcMeDateTime).TotalSeconds); // long meTotalSeconds = (long)Math.Floor(fileInfo.LastWriteTime.ToUniversalTime().Subtract(utcMeDateTime).TotalSeconds);
let now = new Date(); const now = new Date();
let start = new Date(now.getFullYear(), 0, 0); const time = now.getTime();
let diff = (now - start) + ((start.getTimezoneOffset() - now.getTimezoneOffset()) * 60 * 1000); const year = now.getFullYear();
let oneDay = 1000 * 60 * 60 * 24; const start = new Date(year, 0, 0);
let day = Math.floor(diff / oneDay); const oneDay = 1000 * 60 * 60 * 24;
const timezoneOffset = now.getTimezoneOffset();
const diff = (now - start) + ((start.getTimezoneOffset() - timezoneOffset) * 60 * 1000);
const day = Math.floor(diff / oneDay);
console.log('Day of year: ' + day); console.log('Day of year: ' + day);
var season = now.getFullYear() + "-"; var season = year + "-";
if (day < 78) if (day < 78)
season = season + "0.Winter"; season = season + "0.Winter";
else if (day < 124) else if (day < 124)
@ -39,13 +42,16 @@ else if (day < 354)
season = season + "6.Fall"; season = season + "6.Fall";
else else
season = season + "7.Winter"; season = season + "7.Winter";
let timezoneOffset = now.getTimezoneOffset(); let seconds = time.valueOf() + timezoneOffset;
let seconds = now.getTime().valueOf() + timezoneOffset;
let epoch = seconds * 10000; let epoch = seconds * 10000;
let ticks = epoch + 621355968000000000; let ticks = epoch + 621355968000000000;
let dateText = seconds + " - " + ticks + " - " + now.toString(); let dateText = seconds + " - " + ticks + " - " + now.toString();
console.log("dateText: " + dateText); console.log("dateText: " + dateText);
console.log("end"); console.log("end");
let original = "d:\\5-Other-Small\\Kanban\\Year-Season\\2025\\2025-0.Winter\\1737913505637";
let segments = original.split('\\');
let path = segments.slice(0, -3).join('\\') + '\\2021\\2021-0.Summer\\123';
console.log(path);
// epoch: 25201000 // epoch: 25201000
// ticks: 638665132483790000 // ticks: 638665132483790000
// dateText: 638665132483790000 - Wed Nov 06 2024 10:55:58 GMT-0700 (Mountain Standard Time) // dateText: 638665132483790000 - Wed Nov 06 2024 10:55:58 GMT-0700 (Mountain Standard Time)