Move Bank PDF files to Year Month
This commit is contained in:
parent
3070fee04c
commit
9d612d3d3d
25
.vscode/launch.json
vendored
25
.vscode/launch.json
vendored
@ -13,17 +13,26 @@
|
|||||||
"args": [
|
"args": [
|
||||||
"s",
|
"s",
|
||||||
"X",
|
"X",
|
||||||
"Y:/TRendlog",
|
"D:/5-Other-Small/Proxmox/ffnm",
|
||||||
"Day-Helper-2025-01-14",
|
"Day-Helper-2025-01-26",
|
||||||
"New folder*|202*",
|
"*.txt",
|
||||||
"yyyy-MM-dd",
|
"MM/dd/yy",
|
||||||
"444",
|
"Statement Period",
|
||||||
"555",
|
"WOODS,JASON P",
|
||||||
"666",
|
"666",
|
||||||
"777",
|
"777",
|
||||||
"888",
|
"888",
|
||||||
"999"
|
"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",
|
||||||
"stopAtEntry": false
|
"stopAtEntry": false
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -27,11 +27,13 @@
|
|||||||
"Kanban",
|
"Kanban",
|
||||||
"kanbn",
|
"kanbn",
|
||||||
"Kofax",
|
"Kofax",
|
||||||
|
"Linc",
|
||||||
"mesfs",
|
"mesfs",
|
||||||
"NpgSql",
|
"NpgSql",
|
||||||
"NSFX",
|
"NSFX",
|
||||||
"OBJE",
|
"OBJE",
|
||||||
"onenote",
|
"onenote",
|
||||||
|
"PDFC",
|
||||||
"Permyriad",
|
"Permyriad",
|
||||||
"pged",
|
"pged",
|
||||||
"Phares",
|
"Phares",
|
||||||
|
93
ADO2025/PI4/Helper-2025-01-26.cs
Normal file
93
ADO2025/PI4/Helper-2025-01-26.cs
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.ADO2025.PI4;
|
||||||
|
|
||||||
|
internal static partial class Helper20250126
|
||||||
|
{
|
||||||
|
|
||||||
|
private static void Move(string file, string fileName, string checkFile, List<string> foundLines, ReadOnlyCollection<DateTime> dateTimes)
|
||||||
|
{
|
||||||
|
string checkDirectory = Path.Combine(Path.GetDirectoryName(file) ?? throw new Exception(), dateTimes[0].ToString("yyyy-MM"));
|
||||||
|
if (!Directory.Exists(checkDirectory))
|
||||||
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
|
string fileNameB = Path.GetFileName(checkFile);
|
||||||
|
string checkFileB = Path.Combine(checkDirectory, fileName);
|
||||||
|
string checkFileC = Path.Combine(checkDirectory, fileNameB);
|
||||||
|
string contents = string.Join(Environment.NewLine, foundLines);
|
||||||
|
string checkFileD = Path.Combine(checkDirectory, $"{fileName}.txt");
|
||||||
|
if (!File.Exists(checkFileB))
|
||||||
|
File.Move(file, checkFileB);
|
||||||
|
if (!File.Exists(checkFileC))
|
||||||
|
File.Move(checkFile, checkFileC);
|
||||||
|
File.WriteAllText(checkFileD, contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Move(ILogger<Worker> logger, string dateFormat, string file, string checkFile, string fileName, ReadOnlyCollection<string> statementPeriodSegments, List<string> foundLines)
|
||||||
|
{
|
||||||
|
DateTime dateTime;
|
||||||
|
List<DateTime> dateTimes = [];
|
||||||
|
foreach (string check in statementPeriodSegments)
|
||||||
|
{
|
||||||
|
if (!DateTime.TryParseExact(check, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||||
|
continue;
|
||||||
|
dateTimes.Add(dateTime);
|
||||||
|
}
|
||||||
|
if (dateTimes.Count != 2)
|
||||||
|
logger.LogInformation($"Only {dateTimes.Count} date(s) were found in <{fileName}>!");
|
||||||
|
else
|
||||||
|
Move(file, fileName, checkFile, foundLines, dateTimes.AsReadOnly());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Move(ILogger<Worker> logger, string file, string checkFile, string dateFormat, string statementPeriod, string search)
|
||||||
|
{
|
||||||
|
List<string> foundLines = [];
|
||||||
|
bool statementPeriodFound = false;
|
||||||
|
string[]? statementPeriodSegments = null;
|
||||||
|
string fileName = Path.GetFileName(file);
|
||||||
|
string[] lines = File.ReadAllLines(file);
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
if (statementPeriodSegments is not null)
|
||||||
|
{
|
||||||
|
if (line.Contains(search))
|
||||||
|
foundLines.Add(line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (statementPeriodFound)
|
||||||
|
{
|
||||||
|
statementPeriodSegments = line.Split(' ');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!line.Contains(statementPeriod))
|
||||||
|
continue;
|
||||||
|
statementPeriodFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (statementPeriodSegments is null || statementPeriodSegments.Length < 4)
|
||||||
|
logger.LogInformation($"{nameof(statementPeriod)}: {statementPeriod}; wasn't found in <{fileName}>!");
|
||||||
|
else
|
||||||
|
Move(logger, dateFormat, file, checkFile, fileName, statementPeriodSegments.AsReadOnly(), foundLines);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void Move(ILogger<Worker> logger, List<string> args)
|
||||||
|
{
|
||||||
|
string checkFile;
|
||||||
|
string search = args[5];
|
||||||
|
string dateFormat = args[3];
|
||||||
|
string searchPatterns = args[2];
|
||||||
|
string statementPeriod = args[4];
|
||||||
|
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||||
|
string[] files = Directory.GetFiles(sourceDirectory, searchPatterns, SearchOption.AllDirectories);
|
||||||
|
foreach (string file in files)
|
||||||
|
{
|
||||||
|
checkFile = Path.ChangeExtension(file, ".pdf");
|
||||||
|
if (!File.Exists(checkFile))
|
||||||
|
continue;
|
||||||
|
Move(logger, file, checkFile, dateFormat, statementPeriod, search);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -129,6 +129,8 @@ internal static class HelperDay
|
|||||||
ADO2025.PI4.Helper20250101.MoveToDelete(logger, args);
|
ADO2025.PI4.Helper20250101.MoveToDelete(logger, args);
|
||||||
else if (args[1] == "Day-Helper-2025-01-14")
|
else if (args[1] == "Day-Helper-2025-01-14")
|
||||||
ADO2025.PI4.Helper20250114.Rename(logger, args);
|
ADO2025.PI4.Helper20250114.Rename(logger, args);
|
||||||
|
else if (args[1] == "Day-Helper-2025-01-26")
|
||||||
|
ADO2025.PI4.Helper20250126.Move(logger, args);
|
||||||
else
|
else
|
||||||
throw new Exception(appSettings.Company);
|
throw new Exception(appSettings.Company);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,11 @@ internal static class HelperPdfStripperWrapper
|
|||||||
string? Key,
|
string? Key,
|
||||||
char? Parser);
|
char? Parser);
|
||||||
|
|
||||||
|
private const char _Linc = 'L';
|
||||||
|
private const char _Ghost = 'G';
|
||||||
|
private const char _Kofax = 'K';
|
||||||
|
private const char _Stripper = 'S';
|
||||||
|
|
||||||
private static string GetTextFromPDF(string pdfTextStripperFileName, string sourceFileNamePdf, string destinationFileName)
|
private static string GetTextFromPDF(string pdfTextStripperFileName, string sourceFileNamePdf, string destinationFileName)
|
||||||
{
|
{
|
||||||
string result;
|
string result;
|
||||||
@ -28,14 +33,27 @@ internal static class HelperPdfStripperWrapper
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetLincTextFromPDF(string lincPDFCFileName, string sourceFileNamePdf, string destinationFileName)
|
||||||
|
{
|
||||||
|
string result;
|
||||||
|
if (File.Exists(destinationFileName))
|
||||||
|
File.Delete(destinationFileName);
|
||||||
|
string arguments = string.Concat("-i \"", sourceFileNamePdf, "\" -o \"", destinationFileName, "\"");
|
||||||
|
Process? process = Process.Start(lincPDFCFileName, arguments);
|
||||||
|
_ = process?.WaitForExit(30000);
|
||||||
|
if (!File.Exists(destinationFileName))
|
||||||
|
result = string.Empty;
|
||||||
|
else
|
||||||
|
result = File.ReadAllText(destinationFileName);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private static string GetGhostTextFromPDF(string ghostPCLFileName, string sourceFileNamePdf, string destinationFileName)
|
private static string GetGhostTextFromPDF(string ghostPCLFileName, string sourceFileNamePdf, string destinationFileName)
|
||||||
{
|
{
|
||||||
string result;
|
string result;
|
||||||
if (File.Exists(destinationFileName))
|
if (File.Exists(destinationFileName))
|
||||||
File.Delete(destinationFileName);
|
File.Delete(destinationFileName);
|
||||||
//string arguments = $"-i \"{sourceFile}\" -o \"{result}\"";
|
|
||||||
string arguments = $"-dSAFER -dBATCH -dNOPAUSE -dFIXEDMEDIA -dFitPage -dAutoRotatePages=/All -dDEVICEWIDTHPOINTS=792 -dDEVICEHEIGHTPOINTS=612 -sOutputFile=\"{destinationFileName}\" -sDEVICE=pdfwrite \"{sourceFileNamePdf}\"";
|
string arguments = $"-dSAFER -dBATCH -dNOPAUSE -dFIXEDMEDIA -dFitPage -dAutoRotatePages=/All -dDEVICEWIDTHPOINTS=792 -dDEVICEHEIGHTPOINTS=612 -sOutputFile=\"{destinationFileName}\" -sDEVICE=pdfwrite \"{sourceFileNamePdf}\"";
|
||||||
//Process process = Process.Start(configData.LincPDFCFileName, arguments);
|
|
||||||
Process? process = Process.Start(ghostPCLFileName, arguments);
|
Process? process = Process.Start(ghostPCLFileName, arguments);
|
||||||
_ = process?.WaitForExit(30000);
|
_ = process?.WaitForExit(30000);
|
||||||
if (!File.Exists(destinationFileName))
|
if (!File.Exists(destinationFileName))
|
||||||
@ -83,11 +101,11 @@ internal static class HelperPdfStripperWrapper
|
|||||||
d = Path.Combine(d, directoryName);
|
d = Path.Combine(d, directoryName);
|
||||||
if (!string.IsNullOrEmpty(d) && !Directory.Exists(d))
|
if (!string.IsNullOrEmpty(d) && !Directory.Exists(d))
|
||||||
_ = Directory.CreateDirectory(d);
|
_ = Directory.CreateDirectory(d);
|
||||||
char? parser = p is null ? null : p == "S" ? 'S' : p == "G" ? 'G' : p == "K" ? 'K' : null;
|
char? parser = p is null ? null : p == "S" ? _Stripper : p == "G" ? _Ghost : p == "K" ? _Kofax : p == "L" ? _Linc : null;
|
||||||
return new(d, k, parser);
|
return new(d, k, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ParseSave(ILogger log, string pdfTextStripperFileName, string ghostPCLFileName, string kofaxFileName, string destinationDirectory, char parser, string[] files)
|
private static void ParseSave(ILogger log, string pdfTextStripperFileName, string ghostPCLFileName, string kofaxFileName, string lincPDFCFileName, string destinationDirectory, char parser, string[] files)
|
||||||
{
|
{
|
||||||
string text;
|
string text;
|
||||||
string destinationFileName;
|
string destinationFileName;
|
||||||
@ -96,12 +114,14 @@ internal static class HelperPdfStripperWrapper
|
|||||||
foreach (string file in files)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
destinationFileName = Path.Combine(destinationDirectory, $"{file}.txt");
|
destinationFileName = Path.Combine(destinationDirectory, $"{file}.txt");
|
||||||
if (parser == 'S')
|
if (parser == _Kofax)
|
||||||
text = GetTextFromPDF(pdfTextStripperFileName, file, destinationFileName);
|
|
||||||
else if (parser == 'G')
|
|
||||||
text = GetGhostTextFromPDF(ghostPCLFileName, file, destinationFileName);
|
|
||||||
else if (parser == 'K')
|
|
||||||
text = GetKofaxTextFromPDF(kofaxFileName, file, destinationFileName);
|
text = GetKofaxTextFromPDF(kofaxFileName, file, destinationFileName);
|
||||||
|
else if (parser == _Linc)
|
||||||
|
text = GetLincTextFromPDF(lincPDFCFileName, file, destinationFileName);
|
||||||
|
else if (parser == _Ghost)
|
||||||
|
text = GetGhostTextFromPDF(ghostPCLFileName, file, destinationFileName);
|
||||||
|
else if (parser == _Stripper)
|
||||||
|
text = GetTextFromPDF(pdfTextStripperFileName, file, destinationFileName);
|
||||||
else
|
else
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
log.LogInformation("<{file}> == {length}", Path.GetFileName(file), text.Length);
|
log.LogInformation("<{file}> == {length}", Path.GetFileName(file), text.Length);
|
||||||
@ -135,35 +155,56 @@ internal static class HelperPdfStripperWrapper
|
|||||||
|
|
||||||
internal static void ParseSave(ILogger log, List<string> args)
|
internal static void ParseSave(ILogger log, List<string> args)
|
||||||
{
|
{
|
||||||
string pdfTextStripperFileName = Path.Combine(AppContext.BaseDirectory, "PDF-Text-Stripper.exe");
|
// <ItemGroup>
|
||||||
if (!File.Exists(pdfTextStripperFileName))
|
// <PackageReference Include="Infineon.Mesa.PDF.Text.Stripper" Version="4.8.0.1"><NoWarn>NU1701</NoWarn></PackageReference>
|
||||||
log.LogInformation("exe <{pdfTextStripperFileName}> doesn't exist!", pdfTextStripperFileName);
|
// </ItemGroup>
|
||||||
|
// <ItemGroup>
|
||||||
|
// <None Include="\\mestsa003.infineon.com\EC_EAFRepository\Staging\DeploymentStorage\GhostPCL\gpcl6win64\gpcl6dll64.dll">
|
||||||
|
// <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
// </None>
|
||||||
|
// <None Include="\\mestsa003.infineon.com\EC_EAFRepository\Staging\DeploymentStorage\GhostPCL\gpcl6win64\gpcl6win64.exe">
|
||||||
|
// <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
// </None>
|
||||||
|
// <None Include="\\mestsa003.infineon.com\EC_EAFRepository\Staging\DeploymentStorage\LincPDFC\v2.6.6.21\LincPDFC.exe">
|
||||||
|
// <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
// </None>
|
||||||
|
// </ItemGroup>
|
||||||
|
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||||
|
Input input = GetInput(args);
|
||||||
|
if (string.IsNullOrEmpty(input.DestinationDirectory))
|
||||||
|
log.LogInformation("-d <{DestinationDirectory}> wasn't supplied!", nameof(input.DestinationDirectory));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string ghostPCLFileName = Path.Combine(AppContext.BaseDirectory, "gPcl6win64.exe");
|
if (input.Parser is null)
|
||||||
if (!File.Exists(ghostPCLFileName))
|
log.LogInformation("-p <{Parser}> wasn't supplied!", nameof(input.Parser));
|
||||||
log.LogInformation("exe <{ghostPCLFileName}> doesn't exist!", ghostPCLFileName);
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string kofaxFileName = "C:/Program Files (x86)/Kofax/Power PDF 50/batchConverter.com";
|
string pdfTextStripperFileName = Path.Combine(AppContext.BaseDirectory, "PDF-Text-Stripper.exe");
|
||||||
if (!File.Exists(kofaxFileName))
|
if (input.Parser == _Stripper && !File.Exists(pdfTextStripperFileName))
|
||||||
log.LogInformation("exe <{kofaxFileName}> doesn't exist!", kofaxFileName);
|
log.LogInformation("exe <{pdfTextStripperFileName}> doesn't exist!", pdfTextStripperFileName);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Input input = GetInput(args);
|
string ghostPCLFileName = Path.Combine(AppContext.BaseDirectory, "gPcl6win64.exe");
|
||||||
if (string.IsNullOrEmpty(input.DestinationDirectory))
|
if (input.Parser == _Ghost && !File.Exists(ghostPCLFileName))
|
||||||
log.LogInformation("-d <{DestinationDirectory}> wasn't supplied!", nameof(input.DestinationDirectory));
|
log.LogInformation("exe <{ghostPCLFileName}> doesn't exist!", ghostPCLFileName);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (input.Parser is null)
|
string kofaxFileName = "C:/Program Files (x86)/Kofax/Power PDF 50/batchConverter.com";
|
||||||
log.LogInformation("-p <{Parser}> wasn't supplied!", nameof(input.Parser));
|
if (input.Parser == _Kofax && !File.Exists(kofaxFileName))
|
||||||
|
log.LogInformation("exe <{kofaxFileName}> doesn't exist!", kofaxFileName);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string[] files = Directory.GetFiles(args[0], "*.pdf", SearchOption.TopDirectoryOnly);
|
string lincPDFCFileName = Path.Combine(AppContext.BaseDirectory, "LincPDFC.exe");
|
||||||
if (files.Length == 0)
|
if (input.Parser == _Kofax && !File.Exists(lincPDFCFileName))
|
||||||
log.LogInformation("Length == {length}", files.Length);
|
log.LogInformation("exe <{lincPDFCFileName}> doesn't exist!", lincPDFCFileName);
|
||||||
else
|
else
|
||||||
ParseSave(log, pdfTextStripperFileName, ghostPCLFileName, kofaxFileName, input.DestinationDirectory, input.Parser.Value, files);
|
{
|
||||||
|
string[] files = Directory.GetFiles(sourceDirectory, "*.pdf", SearchOption.TopDirectoryOnly);
|
||||||
|
if (files.Length == 0)
|
||||||
|
log.LogInformation("Length == {length}", files.Length);
|
||||||
|
else
|
||||||
|
ParseSave(log, pdfTextStripperFileName, ghostPCLFileName, kofaxFileName, lincPDFCFileName, input.DestinationDirectory, input.Parser.Value, files);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user