Socket
Socket
Sign inDemoInstall

trash

Package Overview
Dependencies
9
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

trash

Move files and folders to the trash


Version published
Maintainers
1
Created

Readme

Source

trash

Move files and folders to the trash

Build Status

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

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');

(async () => {
	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.

  • trash-cli - CLI for this module
  • empty-trash - Empty the trash
  • del - Delete files and folders

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 19 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc