Does Ruby have mkdir -p?

Possible duplicate:
How to create catalogs recursively in ruby?

In Ruby, how can I do:

mkdir -p cool/beans 
  • Here is what I came up with:

     Dir.mkdir('cool') unless File.directory?('cool') cool_beans_path = File.join('cool', 'beans') Dir.mkdir(cool_beans_path) unless File.directory?(cool_beans_path) 

    But is there a better way?

  • I know I could:

     system('mkdir', '-p', File.join('cool', 'beans')) 

    But it is not platform independent, is it? For example, it works on a Mac, but not on Windows, right?

+49
ruby file directory path mkdir
Jul 13 '12 at 2:29
source share
1 answer
 require 'fileutils' FileUtils.mkdir_p 'cool/beans' 
+96
Jul 13 '12 at 4:28
source share



All Articles