Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • PDF Invoice Generator
Menu

Node.js empty-trash Module to Empty Recycle Bin & Trash and Delete Specific Files in Javascript

Posted on November 5, 2022

 

 

Welcome folks today in this blog post we will be deleting specific files with specific extensions and transfer those files to the trash and recycle bin in javascript. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

In order to get started you need to initialize a new node.js project by executing the below command as shown below

 

 

npm init -y

 

 

This will create the package.json file inside the project. Here we need to install the below libraries as shown below

 

 

npm i trash

 

 

This will install the above module where it will delete the files to recycle bin using the trash module

 

 

Now we first of all add the type attribute inside the package.json file and we need to provide the value module. This will help in using the import statement.

 

 

 

 

 

Now we need to copy paste the index.js file

 

 

JavaScript
1
2
3
import trash from 'trash'
 
await trash(['*.png'])

 

 

As you can see we are importing the trash module and then we are calling the trash() method and inside it we are providing the arrray of files paths and here we are using the pattern of files along side with extension. Here we are selecting all the png image files using .png extension and now if you execute the node.js app it will delete all the png image files from the root directory.

 

 

Deleting the RecycleBin Automatically

 

 

Now we need to delete all the files from the recycle bin automatically. Many times you need to manually delete files from recycle bin. For this we need to install a node.js module which is shown below

 

 

npm i empty-trash

 

 

As you can see now we need to copy paste the index.js file as shown below

 

 

JavaScript
1
2
3
import emptyTrash from 'empty-trash';
 
await emptyTrash();

 

 

As you can see we are importing the empty-trash module and then we are calling the emptyTrash() method to clear out all the files which are present inside the recycle bin.

 

 

This library also offers the cli version of the module which is shown below.

 

 

First of all we need to install the cli library globally as shown below

 

npm i -g empty-trash-cli

 

 

And now we need to execute the below command to empty the trash and recycle bin.

 

 

 

Recent Posts

  • Python 3 Tkinter to Show Webcam Video & Capture Image Using OpenCV & Pillow Library GUI Desktop App
  • Node.js Express Github OAuth2 Project to Login With Github Using Access Token & Sessions in Browser
  • PHP 7 OAuth2 Google Login & Logout Script to Store User in MySQL Database and Display in Browser
  • Build a Fixed Deposit Interest Calculator Using Amount and Time in Browser Using HTML5 & Javascript
  • Node.js Express Project to Remove Background of Images Using Rembg & Formidable Library in Browser
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme