zerocaffe.in Blog of Uncaffeinated Experiences on Entrepreneurship and Everything Else

16Apr/083

Recursively creating a set of directories in Ruby

class Dir
  def self.mkdirs(p)
     return if File.exists?
     dir, file = File.split(p)
     Dir.mkdirs(dir) if !File.exists?(dir)
     Dir.mkdir(p)
  end
end

#sample usage: Dir.mkdirs('test/tmp/tempest')

Filed under: code, ruby Leave a comment
Comments (3) Trackbacks (0)
  1. Or you could use the ruby built-in version of:

    Dir.mkdir_p “/dir/that/does/not/exist”

  2. @Ari
    There goes my 15 secs of fame to the dumps – showcasing my bad googling skills. Btw, thank you for the tip!

    Btw thank you for providing the link to your site. Its a great resource and my weekend read!


Leave a comment

No trackbacks yet.