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.
Source Code
# File fileutils.rb, line 195 def mkdir_p(list, options = {}) fu_check_options options, OPT_TABLE['mkdir_p'] list = fu_list(list) fu_output_message "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose] return *list if options[:noop] list.map {|path| path.sub(%r</\z>, '') }.each do |path| # optimize for the most common case begin fu_mkdir path, options[: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 |path| begin fu_mkdir path, options[:mode] rescue SystemCallError => err raise unless File.directory?(path) end end end return *list end
<code/>and<pre/>for code samples.