Comments (2)
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.
Thanks! Sounds great 👍
from delete-empty.
Related Issues (12)
- Async and sync produce different results
- Callback doesn't default to an empty function HOT 2
- Calling function fails with cannot find 'matched' module HOT 3
- Node requirement is actually >= 7.6.0 HOT 3
- Do not log when used as dependency in a non-interractive way HOT 3
- you are not zhongyong a HOT 1
- Version 3.0.0 doesnt seem to work. HOT 5
- Consumes a lot of memory HOT 4
- Sometimes callback would never be called HOT 2
- Callback can be called twice HOT 2
- Version 3 does not work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from delete-empty.