Check multiple potential input filenames in csv-normaliser

This commit is contained in:
2024-09-04 20:19:12 +10:00
parent 1cadbcffb4
commit 6aca0bc039

View File

@@ -4,13 +4,15 @@ $options = getopt("", ["folder:", "input:", "output:", "media:"]);
if (isset($options['folder'])) { if (isset($options['folder'])) {
$folder = $options['folder']; $folder = $options['folder'];
if (is_dir($folder)) { if (is_dir($folder)) {
$expectedInputFileName = str_replace("-", " ", strtoupper(basename($folder))) . ".csv"; $expectedInputFileNames = [];
$expectedInputFileNames[] = str_replace("-", " ", strtoupper(basename($folder))) . ".csv";
$expectedInputFileNames[] = strtoupper(basename($folder)) . ".csv";
if (!isset($options['input'])) { if (!isset($options['input'])) {
$expectedInputFile = $folder . DIRECTORY_SEPARATOR . $expectedInputFileName; foreach ($expectedInputFileNames as $expectedInputFileName) {
if (is_file($expectedInputFile)) { $expectedInputFile = $folder . DIRECTORY_SEPARATOR . $expectedInputFileName;
$options['input'] = $expectedInputFile; if (is_file($expectedInputFile)) {
} else { $options['input'] = $expectedInputFile;
error_log("Couldn't find " . $expectedInputFile . "\n"); }
} }
} }
if (!isset($options['output'])) { if (!isset($options['output'])) {