Skip to content
class method

FileUtils.rmdir

(::FileUtils::pathlist list, ?parents: ::boolish, ?noop: ::boolish, ?verbose: ::boolish) -> void
rmdir(list, parents: nil, noop: nil, verbose: nil)

Removes 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, removes the directory at each path in list, by calling: Dir.rmdir(path); see Dir.rmdir:

Example
FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"]
FileUtils.rmdir('tmp4/tmp5')             # => ["tmp4/tmp5"]

Keyword arguments:

  • parents: true - removes successive ancestor directories if empty.

  • noop: true - does not remove directories.

  • verbose: true - prints an equivalent command:

    Example
    FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3], parents: true, verbose: true)
    FileUtils.rmdir('tmp4/tmp5', parents: true, verbose: true)
    

    Output:

    rmdir -p tmp0/tmp1 tmp2/tmp3
    rmdir -p tmp4/tmp5

Raises an exception if a directory does not exist or if for any reason a directory cannot be removed.

Related: methods for deleting.

See also #rmdir .rm .rm_f .remove_file also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0