Search code examples
rubyfileutils

Create Multiple Folders Within One Directory


I am trying to build a simple File Structure with as little LOC as possible, I understand that FileUtils.mkdir_p './this/that/the/other' makes a path. Is there anything in Ruby that makes multiple folders within one directory like FileUtils.mkdir_p './this/{that, foo, bar}/the/other(This does not work)?


Solution

  • %w(that foo bar).each{|dir| FileUtils.mkdir_p( "./this/#{dir}/the/other")}
    

    Note the double quotes, they allow for string interpolation (the execution of code within a string).