E) Everything delete recursive,

Y) Zip file(s) by directory with file,
This commit is contained in:
Mike Phares 2023-10-02 18:14:15 -07:00
parent 219fdda4ec
commit 0772ab582c
19 changed files with 199 additions and 376 deletions

4
.gitignore vendored
View File

@ -328,4 +328,6 @@ ASALocalRun/
# MFractors (Xamarin productivity tool) working folder
.mfractor/
.vscode/Helper/**
.vscode/Helper/**
.kanbn/board*

View File

@ -1,28 +0,0 @@
.kanbn-column-wip .kanbn-column-task-list {
border-color: #6929c4;
}
.kanbn-column-next .kanbn-column-task-list {
border-color: #1192e8;
}
.kanbn-column-wait .kanbn-column-task-list {
border-color: #005d5d;
}
.kanbn-column-later .kanbn-column-task-list {
border-color: #9f1853;
}
.kanbn-column-maybe .kanbn-column-task-list {
border-color: #fa4d56;
}
.kanbn-column-friday .kanbn-column-task-list {
border-color: #570408;
}
.kanbn-column-done .kanbn-column-task-list {
border-color: #198038;
}
.kanbn-task-data-workload {
display: none;
}
.kanbn-task-data-relation {
display: block;
color: #198038;
}

View File

@ -1,234 +0,0 @@
{
"headings": [
{
"name": "Backlog",
"heading": "^:^+Backlog^:"
},
{
"name": "Todo",
"heading": "^:^+Todo^:"
},
{
"name": "In Progress",
"heading": "^:^c»^: ^+In Progress^:"
},
{
"name": "Done",
"heading": "^:^g✓^: ^+Done^:"
}
],
"lanes": [
{
"name": "All tasks",
"columns": [
[
{
"id": "relative-path-to-relative-to-content",
"name": "Relative Path to relative to content",
"description": "- [ ] Update method ConvertLinksForHugo to actual wanted results",
"metadata": {
"created": "2023-07-18T14:50:28.239Z",
"updated": "2023-07-18T14:54:09.060Z",
"assigned": "",
"progress": 0,
"tags": []
},
"subTasks": [],
"relations": [],
"comments": [],
"column": "Backlog",
"workload": 2,
"progress": 0,
"remainingWorkload": 2
},
{
"id": "markdown-links-to-json",
"name": "Markdown links to json",
"description": "",
"metadata": {
"created": "2023-07-18T14:53:27.412Z",
"updated": "2023-07-18T14:53:33.147Z",
"assigned": "",
"progress": 0,
"tags": []
},
"subTasks": [],
"relations": [],
"comments": [],
"column": "Backlog",
"workload": 2,
"progress": 0,
"remainingWorkload": 2
},
{
"id": "markdown-to-json",
"name": "Markdown to json",
"description": "",
"metadata": {
"created": "2023-07-18T14:48:18.667Z",
"updated": "2023-07-18T14:48:18.660Z",
"assigned": "",
"progress": 0,
"tags": []
},
"subTasks": [],
"relations": [],
"comments": [],
"column": "Backlog",
"workload": 2,
"progress": 0,
"remainingWorkload": 2
}
],
[
{
"id": "find-orphan-links",
"name": "Find orphan links",
"description": "",
"metadata": {
"created": "2023-07-08T00:30:27.277Z",
"updated": "2023-07-08T04:49:18.108Z",
"assigned": "",
"progress": 0,
"tags": [],
"started": "2023-07-08T04:41:56.433Z"
},
"subTasks": [],
"relations": [],
"comments": [],
"column": "Todo",
"workload": 2,
"progress": 0,
"remainingWorkload": 2
}
],
[],
[
{
"id": "break-circular-references",
"name": "Break Circular References",
"description": "",
"metadata": {
"created": "2023-07-08T00:31:18.301Z",
"updated": "2023-07-08T03:13:47.959Z",
"assigned": "",
"progress": 0,
"tags": [],
"started": "2023-07-08T00:31:22.970Z",
"completed": "2023-07-08T03:13:47.959Z"
},
"subTasks": [],
"relations": [],
"comments": [],
"column": "Done",
"workload": 2,
"progress": 1,
"remainingWorkload": 0
},
{
"id": "populate-a-collection-of-file-info-front-matter-and-first-indent-of-1",
"name": "Populate a collection of FileInfo, Front Matter and First # indent of 1",
"description": "",
"metadata": {
"created": "2023-07-08T00:30:00.353Z",
"updated": "2023-07-08T04:08:04.155Z",
"assigned": "",
"progress": 0,
"tags": [],
"started": "2023-07-08T02:17:23.556Z",
"completed": "2023-07-08T04:08:04.156Z"
},
"subTasks": [],
"relations": [],
"comments": [],
"column": "Done",
"workload": 2,
"progress": 1,
"remainingWorkload": 0
},
{
"id": "use-humanizer-on-title-of-links",
"name": "Use humanizer on title of links",
"description": "",
"metadata": {
"created": "2023-07-08T03:22:14.065Z",
"updated": "2023-07-08T04:08:05.706Z",
"assigned": "",
"progress": 0,
"tags": [],
"completed": "2023-07-08T04:08:05.706Z"
},
"subTasks": [],
"relations": [],
"comments": [],
"column": "Done",
"workload": 2,
"progress": 1,
"remainingWorkload": 0
},
{
"id": "convert-files-to-slug-name",
"name": "Convert files to slug name",
"description": "",
"metadata": {
"created": "2023-07-08T00:31:48.068Z",
"updated": "2023-07-08T03:13:39.928Z",
"assigned": "",
"progress": 0,
"tags": [],
"completed": "2023-07-08T03:13:39.928Z"
},
"subTasks": [],
"relations": [],
"comments": [],
"column": "Done",
"workload": 2,
"progress": 1,
"remainingWorkload": 0
},
{
"id": "convert-wiki-links-to-markdown-links",
"name": "Convert Wiki Links to Markdown Links",
"description": "",
"metadata": {
"created": "2023-07-08T00:28:50.180Z",
"updated": "2023-07-08T03:14:14.308Z",
"assigned": "",
"progress": 0,
"tags": [],
"started": "2023-07-08T02:17:20.346Z",
"completed": "2023-07-08T03:14:14.308Z"
},
"subTasks": [],
"relations": [],
"comments": [],
"column": "Done",
"workload": 2,
"progress": 1,
"remainingWorkload": 0
},
{
"id": "add-update-date-in-front-matter",
"name": "Add / Update date in Front Matter",
"description": "- [ ] Maybe done",
"metadata": {
"created": "2023-07-08T00:27:35.865Z",
"updated": "2023-07-08T03:13:43.907Z",
"assigned": "",
"progress": 0,
"tags": [],
"completed": "2023-07-08T03:13:43.907Z"
},
"subTasks": [],
"relations": [],
"comments": [],
"column": "Done",
"workload": 2,
"progress": 1,
"remainingWorkload": 0
}
]
]
}
]
}

Binary file not shown.

View File

@ -5,8 +5,9 @@ completedColumns:
- Done
dateFormat: mm/dd
taskTemplate: '^+^_${overdue ? ''^R'' : ''''}${name}^: ${relations ? (''\n^-^/^g'' + relations.reduce((accumulator, currentValue) => accumulator.task + currentValue.task + '' '', '''')) : ''''}'
created: 2023-07-06T21:45:24.551Z
updated: 2023-07-07T03:46:47.454Z
created: "2023-10-01T18:07:00.085Z"
updated: "2023-10-01T18:07:00.085Z"
type: "Kanban"
---
# File File Helper

View File

@ -1,12 +0,0 @@
---
created: "2023-07-21T21:06:45.447Z"
updated: "2023-07-21T21:06:45.448Z"
assigned: ""
progress: 0
completed: "2023-07-08T03:13:43.907Z"
type: "note"
---
# Add / Update date in Front Matter
- [ ] Maybe done

View File

@ -1,11 +0,0 @@
---
created: "2023-07-21T21:06:45.449Z"
updated: "2023-07-21T21:06:45.449Z"
assigned: ""
progress: 0
started: "2023-07-08T00:31:22.970Z"
completed: "2023-07-08T03:13:47.959Z"
type: "note"
---
# Break Circular References

View File

@ -1,10 +0,0 @@
---
created: "2023-07-21T21:06:45.451Z"
updated: "2023-07-21T21:06:45.451Z"
assigned: ""
progress: 0
completed: "2023-07-08T03:13:39.928Z"
type: "note"
---
# Convert files to slug name

View File

@ -1,11 +0,0 @@
---
created: "2023-07-21T21:06:45.453Z"
updated: "2023-07-21T21:06:45.453Z"
assigned: ""
progress: 0
started: "2023-07-08T02:17:20.346Z"
completed: "2023-07-08T03:14:14.308Z"
type: "note"
---
# Convert Wiki Links to Markdown Links

View File

@ -1,10 +0,0 @@
---
created: "2023-07-21T21:06:45.455Z"
updated: "2023-07-21T21:06:45.456Z"
assigned: ""
progress: 0
started: "2023-07-08T04:41:56.433Z"
type: "note"
---
# Find orphan links

View File

@ -1,9 +0,0 @@
---
type: "kanbn"
created: "2023-07-21T21:06:45.457Z"
updated: "2023-07-21T21:06:45.457Z"
assigned: ""
progress: 0
---
# Markdown links to json

View File

@ -1,9 +0,0 @@
---
type: "kanbn"
created: "2023-07-21T21:06:45.459Z"
updated: "2023-07-21T21:06:45.459Z"
assigned: ""
progress: 0
---
# Markdown to json

View File

@ -1,11 +0,0 @@
---
created: "2023-07-21T21:06:45.460Z"
updated: "2023-07-21T21:06:45.461Z"
assigned: ""
progress: 0
started: "2023-07-08T02:17:23.556Z"
completed: "2023-07-08T04:08:04.156Z"
type: "note"
---
# Populate a collection of FileInfo, Front Matter and First # indent of 1

View File

@ -1,10 +0,0 @@
---
type: "kanbn"
created: "2023-07-21T21:06:45.462Z"
updated: "2023-07-21T21:06:45.462Z"
assigned: ""
progress: 0
completed: "2023-07-19T04:40:41.523Z"
---
# Relative Path to relative to content

View File

@ -1,10 +0,0 @@
---
created: "2023-07-21T21:06:45.465Z"
updated: "2023-07-21T21:06:45.465Z"
assigned: ""
progress: 0
completed: "2023-07-08T04:08:05.706Z"
type: "note"
---
# Use humanizer on title of links

View File

@ -79,8 +79,102 @@ internal static class HelperDeleteEmptyDirectories
internal static void DeleteOldLogFilesAndDeleteEmptyDirectories(ILogger<Worker> logger, string rootDirectory)
{
long ticks = DateTime.Now.AddHours(-120).Ticks;
DeleteOldLogFilesAndDeleteEmptyDirectories(logger, ticks, "*.log", rootDirectory);
DeleteOldLogFilesAndDeleteEmptyDirectories(logger, ticks, "*.log.*", rootDirectory);
DeleteOldLogFilesAndDeleteEmptyDirectories(logger, ticks, "*.log*", rootDirectory);
}
internal static void EverythingDeleteRecursive(ILogger<Worker> logger, string rootDirectory)
{
if (!Path.GetFileName(rootDirectory).StartsWith("_ EverythingDeleteRecursive "))
logger.LogInformation("Directory name must start with {<rootDirectory>}", rootDirectory);
else
{
string[] directories2;
string[] directories3;
string[] directories4;
string[] directories5;
bool errorHappened = false;
string[] directories1 = Directory.GetDirectories(rootDirectory, "*", SearchOption.TopDirectoryOnly);
foreach (string directory1 in directories1)
{
directories2 = Directory.GetDirectories(directory1, "*", SearchOption.TopDirectoryOnly);
foreach (string directory2 in directories2)
{
directories3 = Directory.GetDirectories(directory2, "*", SearchOption.TopDirectoryOnly);
foreach (string directory3 in directories3)
{
directories4 = Directory.GetDirectories(directory3, "*", SearchOption.TopDirectoryOnly);
foreach (string directory4 in directories4)
{
directories5 = Directory.GetDirectories(directory4, "*", SearchOption.TopDirectoryOnly);
foreach (string directory5 in directories5)
{
try
{
logger.LogInformation("{directoryName}", Path.GetFileName(directory5));
Directory.Delete(directory5, recursive: true);
}
catch (Exception)
{ errorHappened = true; }
}
if (!errorHappened)
{
try
{
logger.LogInformation("{directoryName}", Path.GetFileName(directory4));
Directory.Delete(directory4, recursive: true);
}
catch (Exception)
{ errorHappened = true; }
}
}
if (!errorHappened)
{
try
{
logger.LogInformation("{directoryName}", Path.GetFileName(directory3));
Directory.Delete(directory3, recursive: true);
}
catch (Exception)
{ errorHappened = true; }
}
}
if (!errorHappened)
{
try
{
logger.LogInformation("{directoryName}", Path.GetFileName(directory2));
Directory.Delete(directory2, recursive: true);
}
catch (Exception)
{ errorHappened = true; }
}
}
if (!errorHappened)
{
try
{
logger.LogInformation("{directoryName}", Path.GetFileName(directory1));
Directory.Delete(directory1, recursive: true);
}
catch (Exception)
{ errorHappened = true; }
}
}
if (!errorHappened)
{
try
{
logger.LogInformation("{directoryName}", Path.GetFileName(rootDirectory));
Directory.Delete(rootDirectory, recursive: true);
}
catch (Exception)
{ errorHappened = true; }
}
if (!errorHappened)
logger.LogInformation("Finished");
else
logger.LogInformation("Error(s) occurred");
}
}
}

View File

@ -5,7 +5,7 @@ using System.Text.RegularExpressions;
namespace File_Folder_Helper.Helpers;
internal static partial class HelperZipFilesByDate
internal static partial class HelperZipFilesBy
{
[GeneratedRegex("[a-zA-Z0-9]{1,}")]
@ -267,4 +267,82 @@ internal static partial class HelperZipFilesByDate
return result;
}
private static void ZipDirectory(ILogger<Worker> logger, string directory)
{
logger.LogInformation("{directory}", directory);
string[] files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories);
using ZipArchive zip = ZipFile.Open($"{directory}.zip", ZipArchiveMode.Create);
foreach (string file in files)
{
_ = zip.CreateEntryFromFile(file, Path.GetFileName(file));
File.Delete(file);
}
Directory.Delete(directory, recursive: true);
}
internal static void ZipFilesByDirectoryWithFile(ILogger<Worker> logger, string sourceDirectory)
{
string[] files1;
string[] files2;
string[] files3;
string[] files4;
string[] files5;
string[] directories2;
string[] directories3;
string[] directories4;
string[] directories5;
string[] directories1 = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly);
foreach (string directory1 in directories1)
{
files1 = Directory.GetFiles(directory1, "*", SearchOption.TopDirectoryOnly).Where(l => !l.EndsWith(".zip")).ToArray();
if (files1.Length > 0)
{
ZipDirectory(logger, directory1);
continue;
}
directories2 = Directory.GetDirectories(directory1, "*", SearchOption.TopDirectoryOnly);
foreach (string directory2 in directories2)
{
files2 = Directory.GetFiles(directory2, "*", SearchOption.TopDirectoryOnly).Where(l => !l.EndsWith(".zip")).ToArray();
if (files2.Length > 0)
{
ZipDirectory(logger, directory2);
continue;
}
directories3 = Directory.GetDirectories(directory2, "*", SearchOption.TopDirectoryOnly);
foreach (string directory3 in directories3)
{
files3 = Directory.GetFiles(directory3, "*", SearchOption.TopDirectoryOnly).Where(l => !l.EndsWith(".zip")).ToArray();
if (files3.Length > 0)
{
ZipDirectory(logger, directory3);
continue;
}
directories4 = Directory.GetDirectories(directory3, "*", SearchOption.TopDirectoryOnly);
foreach (string directory4 in directories4)
{
files4 = Directory.GetFiles(directory4, "*", SearchOption.TopDirectoryOnly).Where(l => !l.EndsWith(".zip")).ToArray();
if (files4.Length > 0)
{
ZipDirectory(logger, directory4);
continue;
}
directories5 = Directory.GetDirectories(directory4, "*", SearchOption.TopDirectoryOnly);
foreach (string directory5 in directories5)
{
files5 = Directory.GetFiles(directory5, "*", SearchOption.TopDirectoryOnly);
if (files5.Length == 0)
throw new NotSupportedException("Files are too deep!");
else
{
ZipDirectory(logger, directory5);
continue;
}
}
}
}
}
}
}
}

View File

@ -1,3 +1,8 @@
---
type: "note"
created: "2023-10-01T18:07:24.100Z"
updated: "2023-10-01T18:07:24.100Z"
---
# Introduction
TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
@ -17,4 +22,4 @@ TODO: Explain how other users and developers can contribute to make your code be
If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files:
- [ASP.NET Core](https://github.com/aspnet/Home)
- [Visual Studio Code](https://github.com/Microsoft/vscode)
- [Chakra Core](https://github.com/Microsoft/ChakraCore)
- [Chakra Core](https://github.com/Microsoft/ChakraCore)

View File

@ -30,6 +30,7 @@ public class Worker : BackgroundService
ConsoleKey.B,
ConsoleKey.C,
ConsoleKey.D,
ConsoleKey.E,
ConsoleKey.F,
ConsoleKey.G,
ConsoleKey.H,
@ -47,6 +48,7 @@ public class Worker : BackgroundService
ConsoleKey.U,
ConsoleKey.V,
ConsoleKey.X,
ConsoleKey.Y,
ConsoleKey.Z,
ConsoleKey.Delete
};
@ -94,7 +96,7 @@ public class Worker : BackgroundService
_Logger.LogInformation("B) Save (All Directories),");
_Logger.LogInformation("C) Clipboard (Top Directory Only),");
_Logger.LogInformation("D) Clipboard (All Directories),");
// E
_Logger.LogInformation("E) Everything delete recursive,");
_Logger.LogInformation("F) Find and delete all *.log.* files then empty directories,");
_Logger.LogInformation("G) Genealogical Data Communication,");
_Logger.LogInformation("H) Hardcoded file search and sort,");
@ -114,7 +116,7 @@ public class Worker : BackgroundService
_Logger.LogInformation("V) VSCode Hope Sort,");
// W
_Logger.LogInformation("X) Download,");
// Y
_Logger.LogInformation("Y) Zip file(s) by directory with file,");
_Logger.LogInformation("Z) Zip file(s) by date,");
_Logger.LogInformation("Delete) Delete empty directories,");
consoleKey = Console.ReadKey().Key;
@ -128,6 +130,9 @@ public class Worker : BackgroundService
case ConsoleKey.D:
Helpers.HelperSaveOrCopyContents.SaveOrCopyContents(_Logger, _Args[0], consoleKey);
break;
case ConsoleKey.E:
Helpers.HelperDeleteEmptyDirectories.EverythingDeleteRecursive(_Logger, _Args[0]);
break;
case ConsoleKey.F:
Helpers.HelperDeleteEmptyDirectories.DeleteOldLogFilesAndDeleteEmptyDirectories(_Logger, _Args[0]);
break;
@ -168,7 +173,7 @@ public class Worker : BackgroundService
Helpers.HelperRenameToOldMoveDeleteOldMerge.RenameToOldMoveDeleteOld(_Logger, _Args[0]);
break;
case ConsoleKey.S:
_ = Helpers.HelperZipFilesByDate.SetDateFromZipEntry(_Logger, _Args[0]);
_ = Helpers.HelperZipFilesBy.SetDateFromZipEntry(_Logger, _Args[0]);
break;
case ConsoleKey.T:
Helpers.HelperTooLong.UpdateDateVerifyAndGetTicksDirectories(_Logger, _AppSettings, _Args[0]);
@ -184,8 +189,11 @@ public class Worker : BackgroundService
case ConsoleKey.X:
Helpers.HelperDownload.SaveJson(_Logger, _Args[0]);
break;
case ConsoleKey.Y:
Helpers.HelperZipFilesBy.ZipFilesByDirectoryWithFile(_Logger, _Args[0]);
break;
case ConsoleKey.Z:
_ = Helpers.HelperZipFilesByDate.ZipFilesByDate(_Logger, _Args[0]);
_ = Helpers.HelperZipFilesBy.ZipFilesByDate(_Logger, _Args[0]);
break;
default:
switch (consoleKey)