trash
Move files and folders to the trash
Last updated 9 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install trash 
SYNC missed versions from official npm registry.

trash

Move files and folders to the trash

Works on macOS (10.12+), Linux, and Windows (8+).

Note: The Linux implementation is not very good and not maintained. Help welcome. If no one steps up to help maintain it, I will eventually remove Linux support.

In contrast to fs.unlink, del, and rimraf which permanently delete files, this only moves them to the trash, which is much safer and reversible.

Install

npm install trash

Usage

import trash from 'trash';

await trash(['*.png', '!rainbow.png']);

API

trash(input, options?)

Returns a Promise.

input

Type: string | string[]

Accepts paths and glob patterns.

options

Type: object

glob

Type: boolean
Default: true

Enable globbing when matching file paths.

CLI

To install the trash command, run:

$ npm install --global trash-cli

Info

On macOS, macos-trash is used.
On Linux, the XDG spec is followed.
On Windows, recycle-bin is used.

FAQ

But I can do the same thing with mv

Not really. The mv command isn't cross-platform and moving to trash is not just about moving the file to a "trash" directory. On all OSes you'll run into file conflicts. The user won't easily be able to restore the file. It won't work on an external drive. The trash directory location varies between Windows versions. For Linux, there's a whole spec you need to follow. On macOS, you'll lose the Put back feature.

Related

Current Tags

  • 9.0.0                                ...           latest (4 months ago)

43 Versions

  • 9.0.0                                ...           4 months ago
  • 8.1.1                                ...           2 years ago
  • 8.1.0                                ...           3 years ago
  • 8.0.0                                ...           3 years ago
  • 7.2.0                                ...           3 years ago
  • 7.1.1                                ...           4 years ago
  • 7.1.0                                ...           4 years ago
  • 7.0.0                                ...           4 years ago
  • 6.1.1                                ...           5 years ago
  • 6.1.0                                ...           5 years ago
  • 6.0.0                                ...           5 years ago
  • 5.2.0                                ...           6 years ago
  • 5.1.0                                ...           6 years ago
  • 5.0.0                                ...           6 years ago
  • 4.3.0                                ...           7 years ago
  • 4.2.1                                ...           7 years ago
  • 4.2.0                                ...           7 years ago
  • 4.1.0                                ...           7 years ago
  • 4.0.1                                ...           8 years ago
  • 4.0.0                                ...           8 years ago
  • 3.4.2                                ...           8 years ago
  • 3.4.1                                ...           9 years ago
  • 3.4.0                                ...           9 years ago
  • 3.3.0                                ...           9 years ago
  • 3.2.0                                ...           9 years ago
  • 3.1.2                                ...           9 years ago
  • 3.1.1                                ...           9 years ago
  • 3.1.0                                ...           9 years ago
  • 3.0.0                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.4.1                                ...           10 years ago
  • 1.4.0                                ...           10 years ago
  • 1.3.1                                ...           10 years ago
  • 1.3.0                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.3                                ...           10 years ago
  • 1.1.2                                ...           10 years ago
  • 1.1.1                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.1.2                                ...           10 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
Maintainers (2)
Downloads
Total 69
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dev Dependencies (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE