Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
FileUtils.mkdir
# File tmp/rubies/ruby-4.1.0-preview1/lib/fileutils.rb, line 346
def mkdir(list, mode: nil, noop: nil, verbose: nil)
list = fu_list(list)
fu_output_message "mkdir #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose
return if noop
list.each do |dir|
fu_mkdir dir, mode
end
end
Argument paths may be one path or an array of paths; each must be interpretable as a path.
By default, creates a directory entry at each of the given paths; each directory has permissions 0775; returns an array of the paths:
FileUtils.mkdir('foo') # => ["foo"] FileUtils.mkdir(%w[bar baz]) # => ["bar", "baz"] File.stat(Dir.new('foo')).mode.to_s(8) # => "40775" File.stat(Dir.new('bar')).mode.to_s(8) # => "40775" File.stat(Dir.new('baz')).mode.to_s(8) # => "40775" FileUtils.rmdir(%w[foo bar baz]) # => ["foo", "bar", "baz"]
Raises an exception if for any reason a directory cannot be created; a common reason is that the directory already exists.
With keyword argument mode given, creates directories with the given permissions:
FileUtils.mkdir('bar', mode: 0664) File.stat(Dir.new('bar')).mode.to_s(8) # => "40664" FileUtils.rmdir('bar')
With keyword argument noop given as true, does not create directories; returns nil
FileUtils.mkdir('foo', noop: true) # => nil Dir.exist?('foo') # => false
With keyword argument verbose given as true, prints a shell command:
FileUtils.mkdir('foo', verbose: true) FileUtils.mkdir(%w[bar baz], mode: 0644, verbose: true) FileUtils.mkdir(%w[bar baz], mode: 0644, verbose: true, noop: true)
Output:
mkdir foo mkdir -m 644 bar baz mkdir -m 644 bar baz
Note that in the last call above (containing noop: true) the existence of the directory is not checked.
Related: FileUtils.mkdir_p.