Empty the trash

Overview

empty-trash

Empty the trash

Works on macOS, Linux, and Windows.

Install

$ npm install empty-trash

Usage

const emptyTrash = require('empty-trash');

(async () => {
	await emptyTrash();
})();

Info

On macOS, AppleScript is used as it's the only way to do it without incurring permission issues.

On Linux, the XDG spec is followed.

On Windows, empty-recycle-bin is used.

Related

Comments
  • doesn't empty trashes on other partitions

    doesn't empty trashes on other partitions

    I have an ntfs partition mounted in ubuntu and this doesn't empty its trash. The nautilus trash can do that (as it shows an aggregated view of all trashes from all disks).

    The solution might be to list all mounted drives (drivelist), find the correct location of trash folders on these (e.g. /mnt/drive123/.Trash-1000/) and clean all of them.

    If you're interested I could try to make a PR with this sometime.

    bug help wanted 
    opened by tborychowski 3
  • Time out error.

    Time out error.

    $ empty-trash 
    Command failed: osascript -e tell app "Finder" to empty trash
    21:32: execution error: Finder got an error: AppleEvent timed out. (-1712)
    

    Am I missing something?

    BTW:

    $ type emptytrash 
    emptytrash is aliased to `sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl'
    
    opened by hemanth 3
  • Error if trash was already empty OS X El Capitan

    Error if trash was already empty OS X El Capitan

    I am getting this error

    > empty-trash
    Command failed: osascript -e tell app "Finder" to empty trash
    21:32: execution error: „Finder“ hat einen Fehler erhalten: Der Vorgang kann nicht abgeschlossen werden. (-128)
    

    I tried to fix this myself, but unfortunately run-applescript does not support the multi line apple script

    tell application "Finder" 
        set itemCount to count of items in the trash
        if itemCount > 0 then
            empty the trash
        end if
    end tell
    

    and fs.readdir("/Users/miladiir/.Trash") returns null despite the folder being non empty. I think NodeJS and the Mac User Trashes are not friends. This might be some weird quirk on the new OS and rootless, but I don't know.

    To clarify: I would like to run this script automated, so it shouldn't throw errors if they are not critical. Just surprising is not an option.

    opened by Miladiir 1
  • Verbose option

    Verbose option

    I would get it if you think this completely overcomplicates stuff, But I would like to have a verbose function that prints out the current available storage space (one line for each mounted drive), followed by a log of each file that gets deleted (could be limited to only the top-level files and folders) and concluded with a line with the current storage space now that the trash has been emptied (again, one separate line for each mounted drive).

    opened by Niels-NTG 1
  • Use xdg-empty-trash module for Linux

    Use xdg-empty-trash module for Linux

    Python required? Not anymore! You could probably merge this pretty safely but do note that there isn't support for external drives yet, although it's probably highly unlikely someone will run this from an USB drive or likewise. There will be a fix for that pretty soon anyway.

    opened by kevva 1
  • PSA: Sophos will tag empty-trash as PUA

    PSA: Sophos will tag empty-trash as PUA

    This is not really an issue, but I found Sophos Home (a free anti-virus product), removed an old version of empty-trash from .npm cache and tag it as NirCmd (PUA, as in potentially unwanted app), even though I am on macOS.

    This is not consistent across releases or even Sophos itself (see the virustotal link, enterprise version didn't warn users), if I look at logs I see internally Sophos still consider latest release to be PUA, but didn't warning users, presumably it doesn't cross a certain score threshold.

    Anyway, just reporting and closing this issue...

    Reference:

    • https://www.sophos.com/en-us/threat-center/threat-analyses/adware-and-puas/NirCmd/detailed-analysis.aspx
    • https://www.virustotal.com/en/file/2d474cc0c764c869bc3728f26bc20879f892ecc8751c4d403f6333b19b3fb3e3/analysis/1483718593/
    opened by bitinn 0
Releases(v4.0.0)
  • v4.0.0(Oct 14, 2021)

  • v3.0.0(Apr 12, 2019)

    Breaking:

    • Require Node.js 8 3b23de7

    Enhancements:

    • Update dependencies (#14) 0020a6e
    • Add TypeScript definition (#14) 0020a6e

    https://github.com/sindresorhus/empty-trash/compare/v2.1.1...v3.0.0

    Source code(tar.gz)
    Source code(zip)
Owner
Sindre Sorhus
Full-Time Open-Sourcerer. Wants more empathy & kindness in open source. Focuses on Swift & JavaScript. Makes macOS apps, CLI tools, npm packages. Likes unicorns
Sindre Sorhus
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
Move files and directories to the 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 maintain

Sindre Sorhus 2.4k Dec 29, 2022
An open source community powered Discord bot to stop and remove the trash from the SW workshop.

SW Anti Reuploads & Trash Discord bot An open source community powered Discord bot to stop and remove the trash from the SW workshop. SW Discord · Cre

SIMPLE MARK 4 Jun 20, 2022
A simple Discord empty bot.

Discord Level Bot Kurulum İlk olarak bilgisayarına Node JS indir. Daha sonra bir MongoDB hesabı oluştur ve connection linki al. Eğer bunu yapmayı bilm

Theark 21 Jun 8, 2022
Empty project with configured webpack, type script and es-lint

Empty project template Empty project with configured webpack, typescript and es-lint Easy to use: Download project files Go to project root directory

Kris Casper 56 Dec 20, 2022
KWin Script to switch to the next or previous non empty virtual desktop

kwin-cycle-non-empty-desktops KWin Script to switch to the next or previous non empty virtual desktop. Installation Method 1: From the KDE Store Go to

Shaan Subbaiah 1 Dec 5, 2022
A simple CLI Tools to Empty Crypto Wallet & Send to your other Wallet Address

A simple CLI tools to empty crypto wallet & send to your other wallet, Build with Nodejs using Ethers API Run Locally Clone the project git clone ht

Raihan Ramadhani 11 Dec 29, 2022
SAP Community Code Challenge: This repository contains an empty OpenUI5 application and end-to-end tests written with wdi5. Take part in the challenge and develop an app that passes the tests.

SAP Community Code Challenge - UI5 The change log describes notable changes in this package. Description This repository is the starting point for the

SAP Samples 8 Oct 24, 2022