javascript methods for sequence to readable date
c# like java for PI5 Helper 2025-02-19 more updates for Compare
This commit is contained in:
@ -1,19 +1,18 @@
|
||||
using File_Folder_Helper.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using File_Folder_Helper.Helpers;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
internal static partial class Helper20250321
|
||||
{
|
||||
internal static partial class Helper20250321 {
|
||||
|
||||
private record Record(string Directory,
|
||||
string File,
|
||||
ThreeDeep ThreeDeep)
|
||||
{
|
||||
ThreeDeep ThreeDeep) {
|
||||
|
||||
public static ReadOnlyCollection<Record> GetCollection(string sourceDirectory, string searchPattern, string[] files)
|
||||
{
|
||||
public static ReadOnlyCollection<Record> GetCollection(string sourceDirectory, string searchPattern, string[] files) {
|
||||
List<Record> results = [];
|
||||
Record record;
|
||||
string directory;
|
||||
@ -21,8 +20,7 @@ internal static partial class Helper20250321
|
||||
bool json = searchPattern.Contains(".json");
|
||||
bool check = searchPattern.Split('.').Length == 3;
|
||||
ReadOnlyCollection<ThreeDeep> collection = ThreeDeep.GetCollection(files);
|
||||
foreach (ThreeDeep threeDeep in collection)
|
||||
{
|
||||
foreach (ThreeDeep threeDeep in collection) {
|
||||
if (!json && check)
|
||||
fileNameWithoutExtension = threeDeep.DirectoryName;
|
||||
else if (!json && !check)
|
||||
@ -32,19 +30,15 @@ internal static partial class Helper20250321
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
directory = $"{fileNameWithoutExtension[^1]}{fileNameWithoutExtension[^3..][..2]}";
|
||||
if (json || (!json && !check))
|
||||
{
|
||||
if (json || (!json && !check)) {
|
||||
record = new(Directory: Path.Combine(sourceDirectory, "new-a", directory),
|
||||
File: $"{threeDeep.FileNameWithoutExtension}{threeDeep.Extension}",
|
||||
ThreeDeep: threeDeep);
|
||||
}
|
||||
else if (!json && check)
|
||||
{
|
||||
} else if (!json && check) {
|
||||
record = new(Directory: Path.Combine(sourceDirectory, "new-b", directory, threeDeep.DirectoryName),
|
||||
File: $"{threeDeep.FileNameWithoutExtension}{threeDeep.Extension}",
|
||||
ThreeDeep: threeDeep);
|
||||
}
|
||||
else
|
||||
} else
|
||||
throw new NotImplementedException();
|
||||
results.Add(record);
|
||||
}
|
||||
@ -59,17 +53,14 @@ internal static partial class Helper20250321
|
||||
long Length,
|
||||
string DirectoryName,
|
||||
string ParentDirectoryName,
|
||||
string Root)
|
||||
{
|
||||
string Root) {
|
||||
|
||||
public static ReadOnlyCollection<ThreeDeep> GetCollection(string[] files)
|
||||
{
|
||||
public static ReadOnlyCollection<ThreeDeep> GetCollection(string[] files) {
|
||||
List<ThreeDeep> results = [];
|
||||
ThreeDeep record;
|
||||
FileInfo fileInfo;
|
||||
string parentDirectory;
|
||||
foreach (string file in files)
|
||||
{
|
||||
foreach (string file in files) {
|
||||
fileInfo = new(file);
|
||||
parentDirectory = Path.GetDirectoryName(fileInfo.DirectoryName) ?? throw new Exception();
|
||||
record = new(Extension: Path.GetExtension(file),
|
||||
@ -89,14 +80,12 @@ internal static partial class Helper20250321
|
||||
|
||||
}
|
||||
|
||||
internal static void MoveToLast(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
internal static void MoveToLast(ILogger<Worker> logger, List<string> args) {
|
||||
string[] searchPatterns = args[2].Split('|');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
if (searchPatterns.Length == 1)
|
||||
logger.LogInformation("No code for just one!");
|
||||
else
|
||||
{
|
||||
else {
|
||||
HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, sourceDirectory);
|
||||
ReadOnlyCollection<Record> collection = GetCollection(logger, searchPatterns, sourceDirectory);
|
||||
if (collection.Count != 0)
|
||||
@ -108,17 +97,14 @@ internal static partial class Helper20250321
|
||||
}
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<Record> GetCollection(ILogger<Worker> logger, string[] searchPatterns, string sourceDirectory)
|
||||
{
|
||||
private static ReadOnlyCollection<Record> GetCollection(ILogger<Worker> logger, string[] searchPatterns, string sourceDirectory) {
|
||||
string[] files;
|
||||
List<Record> results = [];
|
||||
foreach (string searchPattern in searchPatterns)
|
||||
{
|
||||
foreach (string searchPattern in searchPatterns) {
|
||||
files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length == 0)
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else
|
||||
{
|
||||
else {
|
||||
ReadOnlyCollection<Record> collection = Record.GetCollection(sourceDirectory, searchPattern, files);
|
||||
results.AddRange(collection);
|
||||
}
|
||||
@ -126,25 +112,21 @@ internal static partial class Helper20250321
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static void UseCollection(ReadOnlyCollection<Record> collection)
|
||||
{
|
||||
private static void UseCollection(ReadOnlyCollection<Record> collection) {
|
||||
string fullPath;
|
||||
string checkFile;
|
||||
List<string> distinct = [];
|
||||
foreach (Record record in collection)
|
||||
{
|
||||
foreach (Record record in collection) {
|
||||
if (distinct.Contains(record.Directory))
|
||||
continue;
|
||||
distinct.Add(record.Directory);
|
||||
}
|
||||
foreach (string directory in distinct)
|
||||
{
|
||||
foreach (string directory in distinct) {
|
||||
if (Directory.Exists(directory))
|
||||
continue;
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
}
|
||||
foreach (Record record in collection)
|
||||
{
|
||||
foreach (Record record in collection) {
|
||||
checkFile = Path.Combine(record.Directory, record.File);
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
|
Reference in New Issue
Block a user