How to create directories recursively in ruby?

Viewed 42935

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?

6 Answers

Pathname to the rescue!

Pathname('/a/b/c/d.txt').dirname.mkpath
Related