Skip to content

Commit

Permalink
Create root output directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ThioJoe committed May 21, 2024
1 parent ced81b5 commit a9e8837
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using static FileManager;
using static GmicFilterAnimatorApp.MainForm.NativeMethods;

Expand Down Expand Up @@ -769,7 +770,7 @@ private double[] ParseParamsToDoublesArray(string paramsString, bool silent = fa

private string CreateOutputDirectory(string inputFilePath)
{
string outputDir = "Output";
string outputDir;
// If checkbox to use same directory is checked, get the latest directory and use that
if (checkBoxUseSameOutputDir.Checked)
{
Expand All @@ -784,14 +785,18 @@ private string CreateOutputDirectory(string inputFilePath)
return outputDir;
}

private string DecideLogFilePath(string directoryName)
private string DecideLogFilePath(string outputDirPath)
{
string logFilePath = Path.Combine(directoryName, $"{directoryName}_log.txt");
// Get deepest folder name
string[] directoryParts = outputDirPath.Split(Path.DirectorySeparatorChar);
string folderName = directoryParts[directoryParts.Length - 1];

string logFilePath = Path.Combine(outputDirPath, $"{folderName}_log.txt");
int logFileNumber = 2;
// Check if log file already exists, count up until available number
while (File.Exists(logFilePath))
{
logFilePath = Path.Combine(directoryName, $"{directoryName}_log_{logFileNumber}.txt");
logFilePath = Path.Combine(outputDirPath, $"{folderName}_log_{logFileNumber}.txt");
logFileNumber++;
}

Expand All @@ -814,11 +819,14 @@ private int CountExistingFiles(string outputDir)
// Get the latest directory that exists already, or none if none exist. Uses the input file name as a base, returns the latest directory with the same name.
private string GetLatestDirectory(string inputFilePath, bool getNextAvailable = false)
{
string rootOutputFolder = "Output";
// Extract the file name without extension from the input file path
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(inputFilePath);
string outputDirBase = Path.Combine(rootOutputFolder, fileNameWithoutExtension);

// Initialize the output directory name to the file name without extension
string availableDir = fileNameWithoutExtension;
// Combine the base output folder with the file name without extension to create the initial directory name
string availableDir = outputDirBase;
// This variable will store the name of the latest existing directory found
string latestExisting = null;

Expand All @@ -830,7 +838,7 @@ private string GetLatestDirectory(string inputFilePath, bool getNextAvailable =
{
latestExisting = availableDir;
folderCount++;
availableDir = $"{fileNameWithoutExtension}_{folderCount}";
availableDir = $"{outputDirBase}_{folderCount}";
}

// If getNextAvailable is true, return the next directory name that does not exist
Expand Down

0 comments on commit a9e8837

Please sign in to comment.