I was reading some file IO tutorials for C# and have managed to write out some files, but what if the path I'm given contains directories?
For example, I want to create the file called data/my_file
except data
folder doesn't exist.
The line,
BinaryWriter outFile = new BinaryWriter(File.OpenWrite(path));
where path
is the above string, crashes with the message that part of the path doesn't exist, which means C# isn't creating them as required.
I would like C# to handle all of the messy directory creation and checking for me instead of me having to parse the path and create all of the necessary directories. Is this possible? Otherwise, is there a snippet of code that I can just copy over into my project which will handle anything I might be overlooking (since I don't know much about file management).