I want to write content to a file by a non-trivial path and create all parent directories if they don't exist. So the following code:
mkFile "foo/bar/baz/quux.txt"
will create all directories foo/
, foo/bar/
and foo/bar/baz/
if they don't exist (and the file quux.txt
as well of course). What is the easiest way to implement such a function? Ideally, I would like to see a solution that uses only directory
and filepath
libraries.
createDirectoryIfMissing
? It does all the directory creation you ask for then you just need to write""
to your file (catching any exceptions as you see fit). – CandiecreateDirectoryIfMissing True "foo/bar.txt"
creates two directories and not one directory and one file. – Ferula