Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

FileUtils.mkdir

mkdir(list, mode: nil, noop: nil, verbose: nil)

Creates directories at the paths in the given list (a single path or an array of paths); returns list if it is an array, [list] otherwise.

Argument list or its elements should be interpretable as paths.

With no keyword arguments, creates a directory at each path in list by calling: Dir.mkdir(path, mode); see Dir.mkdir:

Example
FileUtils.mkdir(%w[tmp0 tmp1]) # => ["tmp0", "tmp1"]
FileUtils.mkdir('tmp4')        # => ["tmp4"]

Keyword arguments:

  • mode: <i>mode</i> - also calls File.chmod(mode, path); see File.chmod.

  • noop: true - does not create directories.

  • verbose: true - prints an equivalent command:

    Example
    FileUtils.mkdir(%w[tmp0 tmp1], verbose: true)
    FileUtils.mkdir(%w[tmp2 tmp3], mode: 0700, verbose: true)
    

    Output:

    mkdir tmp0 tmp1
    mkdir -m 700 tmp2 tmp3

Raises an exception if any path points to an existing file or directory, or if for any reason a directory cannot be created.

Related: FileUtils.mkdir_p.

See also #mkdir .makedirs .mkdir_p .ln_sr also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0