Method: FileUtils.makedirs
- Defined in:
- lib/extensions/fileutils/fileutils.rb
.makedirs ⇒ Object
Options: mode noop verbose
Creates a directory and all its parent directories. For example,
FileUtils.mkdir_p '/usr/local/lib/ruby'
causes to make following directories, if it does not exist.
* /usr
* /usr/local
* /usr/local/lib
* /usr/local/lib/ruby
You can pass several directories at a time in a list.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/extensions/fileutils/fileutils.rb', line 229 def mkdir_p(list, = {}) , OPT_TABLE['mkdir_p'] list = fu_list(list) "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if [:verbose] return *list if [:noop] list.map {|path| path.sub(%r</\z>, '') }.each do |path| # optimize for the most common case begin fu_mkdir path, [:mode] next rescue SystemCallError next if File.directory?(path) end stack = [] until path == stack.last # dirname("/")=="/", dirname("C:/")=="C:/" stack.push path path = File.dirname(path) end stack.reverse_each do |dir| begin fu_mkdir dir, [:mode] rescue SystemCallError raise unless File.directory?(dir) end end end return *list end |