Skip to content

Instantly share code, notes, and snippets.

@lqqyt2423
Created March 2, 2019 15:00
Show Gist options
  • Save lqqyt2423/11902f190eb63e6beb6004b2cab37074 to your computer and use it in GitHub Desktop.
Save lqqyt2423/11902f190eb63e6beb6004b2cab37074 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
'use strict';
// 删除文件
const fs = require('fs');
const path = require('path');
const { log } = console;
const cwd = process.cwd();
function eachDir (dir) {
const files = fs.readdirSync(dir, { withFileTypes: true });
files.forEach(f => {
const name = f.name;
const fullname = path.join(dir, name);
console.log(fullname);
if (f.isDirectory()) {
eachDir(fullname);
return;
}
// rm .out
if (/\.out$/.test(name)) {
log('rm:', fullname);
fs.unlinkSync(fullname);
return;
}
// rm 二进制
if (!/.+\./.test(name)) {
log('rm:', fullname);
fs.unlinkSync(fullname);
return;
}
});
}
eachDir(cwd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment