Re: 2 (partially). I would do something like this to create the folder:
if !isdir(outputdir)
mkdir(outputdir) # creates the folder in case it doesn't exist
end
function _writetodir()
# here put the code that writes the file
end
cd(_writetodir, outputdir) # temporarily access to outputdir just to do the writing stuff.
where “outputdir” is a String that contains the full path to the directory where you want the output file to be written.