M
M
Michael Compass2021-07-08 23:40:30
Node.js
Michael Compass, 2021-07-08 23:40:30

How to delete all files from a folder that are less than 100 bytes?

I want to implement deletion from a folder of C:\Users\userprofile\Downloads\pppall files less than 100 bytes?

Here's the code I'm using, but there's an error somewhere.

const fs = require('fs');
const path = 'c:\\Users\\userprofile\\Downloads\\ppp';
const max = 100
 
fs.readdir(path, (err, items) => {
    for (let i=0; i<items.length; i++) {
        const file = path + '\\' + items[i];
        (file => fs.stat(file, (err, stats) => {
      if (!stats.isFile()) return
      if (stats.size < max) {
        console.log('Удаление файла', file);
        console.log(stats.size);
        fs.unlinkSync(file, err => console.log(err))
      }
        }))(file);
    }
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question