trash 0,4,0,0,2 editorconfig travis-ci npm

Move files and folders to the trash

2 years after MIT

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 --save trash

Usage

const trash = require('trash');

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

API

trash(input)

Returns a Promise.

input

Type: Iterable<string>

Accepts paths and glob patterns.

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

Related Repositories

trash-cli

trash-cli

Command line interface to the freedesktop.org trashcan. ...

trash-cli

trash-cli

Move files and folders to the trash ...

empty-trash

empty-trash

Empty the trash ...

node-steam-trash-bot

node-steam-trash-bot

Steam bot that takes any trash from your inventory and sends it to anyone else w ...

empty-trash-cli

empty-trash-cli

Empty the trash ...


Top Contributors

sindresorhus kevva omnidan daleeidd arthurvr konsumer sotojuan mickvangelderen ntwb

Dependencies

package version
escape-string-applescript ^1.0.0
fs-extra ^0.30.0
globby ^6.0.0
path-exists ^3.0.0
pify ^2.3.0
run-applescript ^3.0.0
uuid ^2.0.1
xdg-trashdir ^2.0.0
dev ava *
tempfile ^1.1.1
xo *

Releases

-   v4.0.0 zip tar
-   v3.4.2 zip tar
-   v3.4.1 zip tar
-   v3.4.0 zip tar
-   v3.3.0 zip tar
-   v3.2.0 zip tar
-   v3.1.2 zip tar
-   v3.1.1 zip tar
-   v3.1.0 zip tar
-   v3.0.0 zip tar
-   v2.0.0 zip tar
-   v1.4.1 zip tar
-   v1.4.0 zip tar
-   v1.3.1 zip tar
-   v1.3.0 zip tar
-   v1.2.0 zip tar
-   v1.1.3 zip tar
-   v1.1.2 zip tar
-   v1.1.1 zip tar
-   v1.1.0 zip tar
-   v1.0.0 zip tar
-   v0.1.2 zip tar
-   v0.1.1 zip tar
-   v0.1.0 zip tar