Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Dir.mkdir
Dir.mkdir(dirpath, permissions = 0775) → 0
dir.c
View on GitHub ↗
static VALUE
dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
{
struct mkdir_arg m;
VALUE path, vmode;
int r;
if (rb_scan_args(argc, argv, "11", &path, &vmode) == 2) {
m.mode = NUM2MODET(vmode);
}
else {
m.mode = 0777;
}
path = check_dirname(path);
m.path = RSTRING_PTR(path);
r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_mkdir, &m, RUBY_UBF_IO, 0);
if (r < 0)
rb_sys_fail_path(path);
return INT2FIX(0);
}
Creates a directory in the underlying file system at dirpath with the given permissions; returns zero:
Example
Dir.mkdir('foo') File.stat(Dir.new('foo')).mode.to_s(8)[1..4] # => "0755" Dir.mkdir('bar', 0644) File.stat(Dir.new('bar')).mode.to_s(8)[1..4] # => "0644"
See File Permissions. Note that argument permissions is ignored on Windows.