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

23
.vscode/launch.json vendored
View File

@ -13,26 +13,9 @@
"args": [
"s",
"X",
"D:/5-Other-Small/Proxmox/ffnm",
"Day-Helper-2025-01-26",
"*.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"
],
"D:/5-Other-Small/Kanban-mestsa003/{}/2025/2025_Week_05/223065",
"Day-Helper-2025-02-04",
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"stopAtEntry": false

View File

@ -1,7 +1,9 @@
using File_Folder_Helper.Helpers;
using File_Folder_Helper.Models;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
@ -24,7 +26,7 @@ internal static partial class Helper20240623
private record Input(long? AfterEpochTotalMilliseconds,
string CodeInsiders,
string? DestinationDirectory,
ReadOnlyCollection<string> DestinationDirectories,
string DirectoryFilter,
string Done,
string IndexFile,
@ -379,10 +381,19 @@ internal static partial class Helper20240623
string subTasks = args[3].Replace('_', ' ');
string codeInsiders = args[4].Replace('_', ' ');
string sourceDirectory = Path.GetFullPath(args[0]);
string? destinationDirectory = args.Count < 8 ? null : Path.GetFullPath(args[9]);
long? afterEpochTotalMilliseconds = args.Count < 9 ? null : long.Parse(args[10]);
ReadOnlyCollection<string> tasks = args[6].Split(',').Select(l => l.Replace('_', ' ')).ToArray().AsReadOnly();
Input input = new(afterEpochTotalMilliseconds, codeInsiders, destinationDirectory, directoryFilter, done, indexFile, searchPattern, subTasks, sourceDirectory, tasks);
string[] tasks = args[6].Split(',').Select(l => l.Replace('_', ' ')).ToArray();
long? afterEpochTotalMilliseconds = args.Count < 11 ? null : long.Parse(args[10]);
string[] destinationDirectories = args.Count < 10 ? [] : args.Count < 12 ? [Path.GetFullPath(args[9])] : [Path.GetFullPath(args[9]), Path.GetFullPath(args[11])];
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] != "](")
throw new Exception(JsonSerializer.Serialize(input, InputSourceGenerationContext.Default.Input));
return input;
@ -391,34 +402,39 @@ internal static partial class Helper20240623
private static string? MaybeWriteAndGetIndexFile(Input input, Record record, string? checkDirectory)
{
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 (record.LineNumber.H1 is null)
if (!input.DestinationDirectories.Any(checkDirectory.Contains))
result = null;
else
{
string segment = Path.GetFileName(checkDirectory);
string h1 = record.LineNumber.Lines[record.LineNumber.H1.Value];
DateTime utcEpochDateTime = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
long utcEpochTotalMilliseconds = (long)Math.Floor(DateTime.UtcNow.Subtract(utcEpochDateTime).TotalMilliseconds);
if (!long.TryParse(segment, out long check) || check < input.AfterEpochTotalMilliseconds || check > utcEpochTotalMilliseconds)
if (record.LineNumber.H1 is null)
result = null;
else
{
ReadOnlyCollection<H1AndParamCase> h1ParamCaseCollection = GetH1ParamCaseCollection(input, record.LineNumber.Lines);
if (h1ParamCaseCollection.Count == 0)
string segment = Path.GetFileName(checkDirectory);
string h1 = record.LineNumber.Lines[record.LineNumber.H1.Value];
DateTime utcEpochDateTime = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
long utcEpochTotalMilliseconds = (long)Math.Floor(DateTime.UtcNow.Subtract(utcEpochDateTime).TotalMilliseconds);
if (!long.TryParse(segment, out long check) || check < input.AfterEpochTotalMilliseconds || check > utcEpochTotalMilliseconds)
result = null;
else
{
DateTime dateTime = utcEpochDateTime.AddMilliseconds(check).ToLocalTime();
string seasonName = GetSeasonName(dateTime.DayOfYear);
ReadOnlyCollection<string> directoryNames = HelperDirectory.GetDirectoryNames(checkDirectory);
if (!directoryNames.Contains(dateTime.Year.ToString()) || !directoryNames.Contains($"{dateTime.Year}-{seasonName}") || !directoryNames.Contains(check.ToString()))
ReadOnlyCollection<H1AndParamCase> h1ParamCaseCollection = GetH1ParamCaseCollection(input, record.LineNumber.Lines);
if (h1ParamCaseCollection.Count == 0)
result = null;
else
result = WriteAndGetIndexFile(h1, checkDirectory, h1ParamCaseCollection);
{
DateTime dateTime = utcEpochDateTime.AddMilliseconds(check).ToLocalTime();
string seasonName = GetSeasonName(dateTime.DayOfYear);
ReadOnlyCollection<string> directoryNames = HelperDirectory.GetDirectoryNames(checkDirectory);
if (!directoryNames.Contains(dateTime.Year.ToString()) || !directoryNames.Contains($"{dateTime.Year}-{seasonName}") || !directoryNames.Contains(check.ToString()))
result = null;
else
result = WriteAndGetIndexFile(h1, checkDirectory, h1ParamCaseCollection);
}
}
}
}
@ -478,15 +494,16 @@ internal static partial class Helper20240623
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;
string? indexFile;
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 (!string.IsNullOrEmpty(input.DestinationDirectory) && checkDirectory.Contains(input.DestinationDirectory))
if (input.DestinationDirectories.Count > 0 && input.DestinationDirectories.Any(checkDirectory.Contains))
_ = Directory.CreateDirectory(checkDirectory);
}
if (!Directory.Exists(checkDirectory))
@ -507,6 +524,8 @@ internal static partial class Helper20240623
indexFile = MaybeWriteAndGetIndexFile(input, record, checkDirectory);
if (!string.IsNullOrEmpty(indexFile))
results.Add(indexFile);
else
logger.LogInformation("<{checkDirectory}>", checkDirectory);
}
}
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)
continue;
codeInsidersLine = record.LineNumber.Lines[record.CodeInsidersLine.Value];
fileInfo = GetIndexFileInfo(input, record, codeInsidersLine);
fileInfo = GetIndexFileInfo(logger, input, record, codeInsidersLine);
if (!fileInfo.Exists)
{
checkDirectory = codeInsidersLine[input.CodeInsiders.Length..^1];

View File

@ -16,13 +16,16 @@
// console.log("dateText: " + dateText);
// DateTime utcMeDateTime = new(1980, 1, 17, 0, 0, 0, DateTimeKind.Utc);
// long meTotalSeconds = (long)Math.Floor(fileInfo.LastWriteTime.ToUniversalTime().Subtract(utcMeDateTime).TotalSeconds);
let now = new Date();
let start = new Date(now.getFullYear(), 0, 0);
let diff = (now - start) + ((start.getTimezoneOffset() - now.getTimezoneOffset()) * 60 * 1000);
let oneDay = 1000 * 60 * 60 * 24;
let day = Math.floor(diff / oneDay);
const now = new Date();
const time = now.getTime();
const year = now.getFullYear();
const start = new Date(year, 0, 0);
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);
var season = now.getFullYear() + "-";
var season = year + "-";
if (day < 78)
season = season + "0.Winter";
else if (day < 124)
@ -39,13 +42,16 @@ else if (day < 354)
season = season + "6.Fall";
else
season = season + "7.Winter";
let timezoneOffset = now.getTimezoneOffset();
let seconds = now.getTime().valueOf() + timezoneOffset;
let seconds = time.valueOf() + timezoneOffset;
let epoch = seconds * 10000;
let ticks = epoch + 621355968000000000;
let dateText = seconds + " - " + ticks + " - " + now.toString();
console.log("dateText: " + dateText);
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
// ticks: 638665132483790000
// dateText: 638665132483790000 - Wed Nov 06 2024 10:55:58 GMT-0700 (Mountain Standard Time)