I want to store a file as /a/b/c/d.txt, but I do not know if any of these directories exist and need to recursively create them if necessary. How can one do this in ruby?
Thanks for the pointer! The docs seem to prefer FileUtils.mkdir_p, so I took that...
Jan Limpens
2010-09-10 15:49:40
+2
A:
Try this:
FileUtils.mkdir_p '/a/b/c'
The "_p" is a unix holdover for parent/path you can also use the alias mkpath if that makes more sense for you.
FileUtils.mkpath '/a/b/c'
Reference this page here.
Harmon Wood
2010-09-10 15:49:00
+1. `FileUtils` and `Pathname` are probably *the* most important tools for Ruby shell scripting.
Jörg W Mittag
2010-09-10 17:41:27
A:
If you are running on unixy machines, don't forget you can always run a shell command under ruby by placing it in backticks.
`mkdir -p /a/b/c`
Matthew Schinckel
2010-09-10 16:09:39