trash

Move files and directories to the trash

Github星跟蹤圖

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.

License

MIT © Sindre Sorhus

主要指標

概覽
名稱與所有者sindresorhus/trash
主編程語言JavaScript
編程語言JavaScript (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2014-05-14 17:25:32
推送於2024-07-26 12:21:13
最后一次提交
發布數43
最新版本名稱v9.0.0 (發布於 2024-07-26 14:20:31)
第一版名稱v0.1.0 (發布於 2014-05-14 19:34:23)
用户参与
星數2.6k
關注者數25
派生數80
提交數156
已啟用問題?
問題數91
打開的問題數13
拉請求數26
打開的拉請求數0
關閉的拉請求數10
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?