If I want to write a file to C:/output/results.csv what's a simple way to make the directory if it doesn't exist? I want to do this because CSV.write(path,data) errors if C:/output/ doesn't exist.
mkdir errors if the directory already exists. I am currently doing the following, but is there a safer/cleaner way to do this?
try
mkdir("C:/output")
catch
# if errors, likely already exists
end
Edit:
As one of the commenters pointed out, mkpath will create a directory if it doesn't exist, and in either case will return the directory name.
My question was confounding the usage of mkdir (which errors if directory exists) and mkpath which does not error in that case.