Giter VIP home page Giter VIP logo

Comments (2)

jonschlinkert avatar jonschlinkert commented on May 31, 2024

Wow so sorry, I remember seeing this issue and I was confident I replied to it a long time ago. I also think this should have been done differently. I don't think it would work consistently as it's currently written.

I'll refactor this as soon as I have a chance, to something more like this (I just tested this over the past couple of days locally as I migrated a bunch of data to new hard drives, worked pretty well):

'use strict';

var fs = require('fs');
var path = require('path');
var exists = require('fs-exists-sync');
var del = require('delete');
var ok = require('log-ok');

module.exports = function(cwd) {
  function remove(dir) {
    if (!exists(dir)) return;

    var stat = fs.statSync(dir);
    if (stat && stat.isDirectory() && dir.indexOf(cwd) === 0) {
      var files = fs.readdirSync(dir);

      if (isEmpty(files)) {
        del.sync(dir, {force: true});
        ok('deleted:', dir);
        remove(path.dirname(dir));

      } else {
        files.forEach(function(name) {
          remove(path.join(dir, name));
        });
      }
    }
  }
  return remove(cwd);
};

function isEmpty(files) {
  return files.filter(wanted).length === 0;
}

function wanted(filename) {
  return !isUnwanted(filename);
}

function isUnwanted(filename) {
  return /(?:Thumbs\.db|\.DS_Store)$/i.test(filename);
}

But instead of hardcoding the regex/filter function, I'll update that code to allow a filter function as the second argument. same for the async version

from delete-empty.

roelvangils avatar roelvangils commented on May 31, 2024

Thanks! Sounds great 👍

from delete-empty.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.