Skip to content
class method

FileUtils.rm

(::FileUtils::pathlist list, ?force: ::boolish, ?noop: ::boolish, ?verbose: ::boolish) -> void
rm(list, force: nil, noop: nil, verbose: nil)

Removes entries 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 files at the paths given in list:

Example
FileUtils.touch(['src0.txt', 'src0.dat'])
FileUtils.rm(['src0.dat', 'src0.txt']) # => ["src0.dat", "src0.txt"]

Keyword arguments:

  • force: true - ignores raised exceptions of StandardError and its descendants.

  • noop: true - does not remove files; returns nil.

  • verbose: true - prints an equivalent command:

    Example
    FileUtils.rm(['src0.dat', 'src0.txt'], noop: true, verbose: true)
    

    Output:

    Example
    rm src0.dat src0.txt
    

Related: methods for deleting.

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