Move files and folders to the trash
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib Handle a lot of files on Linux (#65) Feb 26, 2018
media minify images further Oct 13, 2015
.editorconfig Meta tweaks Sep 17, 2017
.gitattributes OS X → macOS Jun 14, 2016
.gitignore Meta tweaks Sep 17, 2017
.npmrc Meta tweaks Sep 17, 2017
.travis.yml Fix tests Aug 29, 2017
index.js Follow-up tweaks for #67 Dec 3, 2017
license Meta tweaks Sep 17, 2017
package.json 4.3.0 Feb 26, 2018
readme.md GitHub now natively supports SVG Apr 20, 2018
test.js Handle a lot of files on Linux (#65) Feb 26, 2018

readme.md

trash

Move files and folders to the trash

Build Status

Works on macOS, Linux, and Windows.

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

const trash = require('trash');

trash(['*.png', '!rainbow.png']).then(() => {
	console.log('done');
});

API

trash(input, [options])

Returns a Promise.

input

Type: Iterable<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

License

MIT © Sindre Sorhus