File::Remove(3) User Contributed Perl Documentation File::Remove(3)

# [NAME](#NAME)

File::Remove - Remove files and directories

# [SYNOPSIS](#SYNOPSIS)

```
    use File::Remove 'remove';
    # removes (without recursion) several files
    remove( '*.c', '*.pl' );
    # removes (with recursion) several directories
    remove( \1, qw{directory1 directory2} );
    # removes (with recursion) several files and directories
    remove( \1, qw{file1 file2 directory1 *~} );
    # removes without globbing:
    remove( \1, {glob => 0}, '*');
    # trashes (with support for undeleting later) several files
    trash( '*~' );
```

# [DESCRIPTION](#DESCRIPTION)

**File::Remove::remove** removes files and directories. It acts like **/bin/rm**, for the most part. Although "unlink" can be given a list of files, it will not remove directories; this module remedies that. It also accepts wildcards, * and ?, as arguments for filenames.

**File::Remove::trash** accepts the same arguments as **remove**, with the addition of an optional, infrequently used "other platforms" hashref.

# [SUBROUTINES](#SUBROUTINES)

## [remove](#remove)

Removes files and directories. Directories are removed recursively like in **rm -rf** if the first argument is a reference to a scalar that evaluates to true. If the first argument is a reference to a scalar, then it is used as the value of the recursive flag. By default it's false so only pass \\1 to it.

If the next argument is a hash reference then it is a key/values of options. Currently, there is one supported option of "'glob' =&gt; 0" which prevents globbing. E.g:

```
    remove(\1, {glob => 0}, '*');
```

Will not remove files globbed by '\*' and will only remove the file called asterisk if it exists.

In list context it returns a list of files/directories removed, in scalar context it returns the number of files/directories removed. The list/number should match what was passed in if everything went well.

## [rm](#rm)

Just calls **remove**. It's there for people who get tired of typing **remove**.

## [clear](#clear)

The "clear" function is a version of "remove" designed for use in test scripts. It takes a list of paths that it will both initially delete during the current test run, and then further flag for deletion at END-time as a convenience for the next test run.

## [trash](#trash)

Removes files and directories, with support for undeleting later. Accepts an optional "other platforms" hashref, passing the remaining arguments to **remove**.

[Win32](#Win32)

Requires Win32::FileOp.

Installation not actually enforced on Win32 yet, since Win32::FileOp has badly failing dependencies at time of writing.

[OS X](#OS)

Requires Mac::Glue.

[Other platforms](#Other)

The first argument to **trash()** must be a hashref with two keys, 'rmdir' and 'unlink', each referencing a coderef. The coderefs will be called with the filenames that are to be deleted.

## [expand](#expand)

**DO NOT USE.** Kept for legacy.

## [undelete](#undelete)

**DO NOT USE.** Kept for legacy.

# [SUPPORT](#SUPPORT)

Bugs should always be submitted via the CPAN bug tracker

&lt;http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Remove&gt;

For other issues, contact the maintainer.

# [AUTHOR](#AUTHOR)

Adam Kennedy &lt;adamk@cpan.org&gt;

# [COPYRIGHT](#COPYRIGHT)

Taken over by Shlomi Fish (&lt;http://www.shlomifish.org/&gt;) while disclaiming all rights and placing his modifications under CC0/public-domain/MIT/any-other-licence.

Some parts copyright 2006 - 2012 Adam Kennedy.

Taken over by Adam Kennedy &lt;adamk@cpan.org&gt; to fix the "deep readonly files" bug, and do some package cleaning.

Some parts copyright 2004 - 2005 Richard Soderberg.

Taken over by Richard Soderberg &lt;perl@crystalflame.net&gt; to port it to File::Spec and add tests.

Original copyright: 1998 by Gabor Egressy, &lt;gabor@vmunix.com&gt;.

This program is free software; you can redistribute and/or modify it under the same terms as Perl itself.

2026-10-26 perl v5.44.0

---

Document: File::Remove(3pm) from perl-file-remove 1.61-r10 (Chainguard OS)
Source: https://github.com/shlomif/File-Remove
