I'm writing a function in Javascript that will verify the existence of a particular kind of file and if it does not exist, then it will copy the file from a known location in a git repository to the correct location.
To do this, I'm also using a function I wrote that verifies the existence of any file (only at certain paths that we've pre-defined). Also, file.exists is a function prebuilt in our IDE.
That function looks like this:
function verifyFileExistence(file, path, existState)
{
var result;
var logMessage;
var resultMessage;
if (existState == true)
{
logMessage = "Verify that \"\"" + file + "\"\" exists.";
result = (File.exists(path + file));
if (result)
{
resultMessage = "\"\"" + file + "\"\" exists.";
}
else
{
resultMessage = "\"\"" + file + "\"\" does not exist.";
}
}
else
{
logMessage = "Verify that \"\"" + file + "\"\" does not exist.";
result = (!File.exists(path + file ));
if (result)
{
resultMessage = "\"\"" + file + "\"\" does not exist.";
}
else
{
resultMessage = "\"\"" + file + "\"\" exists.";
}
}
resultVP(logMessage, resultMessage, result)
}
Side Note: Each of these functions will write results to a log file which is why the different result/log/message variables appear. I left them in because I think they help to show make the logic clear.
So far, my function to check for the specific file type looks something like this:
import {copyFile,verifyFileExistence} from 'Path\\to\\FileUtilityLibrary.js';
function verifyLoadFile(file, path, existState, inFile, outFile)
{
var exist;
exist = (verifyFileExistence(file, path, existState));
if (exist != true)
{
copyFile(inFile,outFile)
}
}
I feel like having this many parameters in the function is inefficient and that maybe there's a more efficient way of handling them. Can I somehow simply this or is this the best way to handle parameters when calling functions inside a function?