End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
FileUtils.mkpath
mkpath(list, mode: nil, noop: nil, verbose: nil)
lib/fileutils.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/fileutils.rb, line 206
def mkdir_p(list, mode: nil, noop: nil, verbose: nil)
list = fu_list(list)
fu_output_message "mkdir -p #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose
return *list if noop
list.each do |item|
path = remove_trailing_slash(item)
stack = []
until File.directory?(path) || File.dirname(path) == path
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
Alias of .mkdir_p
Creates a directory and all its parent directories. For example,
Example
FileUtils.mkdir_p '/usr/local/lib/ruby'
causes to make following directories, if they do not exist.
-
/usr
-
/usr/local
-
/usr/local/lib
-
/usr/local/lib/ruby
You can pass several directories at a time in a list.