Skip to content

Instantly share code, notes, and snippets.

@mailzwj
Last active May 29, 2020 09:37
Show Gist options
  • Save mailzwj/29c771fd9209c7442951715165f35c04 to your computer and use it in GitHub Desktop.
Save mailzwj/29c771fd9209c7442951715165f35c04 to your computer and use it in GitHub Desktop.
查看指定文件夹下,在某个时间点之后发生过变更的文件及变更时间
/**
* 查看指定文件夹下,在某个时间点之后发生过变更的文件及变更时间
*/
const fs = require('fs');
const path = require('path');
const base = '/Users/username/Desktop/Works/Projects/';
const op = 'projectName';
const blackList = ['.git', '.vscode', 'node_modules', '.umi', 'dist', 'opensource'];
const rDirName = /\/([a-z0-9-_.]+)$/i;
const output = [];
const edgeTimeObj = new Date('2019/11/27 00:00:00');
const loop = (entry) => {
output.push(`Entry: ${entry}\n==========`);
let dirName = '';
if (rDirName.test(entry)) {
dirName = RegExp.$1;
} else {
return;
}
if (blackList.includes(dirName)) {
return;
}
const stat = fs.statSync(entry);
if (stat.isDirectory()) {
const ls = fs.readdirSync(entry);
ls.forEach(f => {
const fpath = path.join(entry, f);
const fstat = fs.statSync(fpath);
if (fstat.isDirectory()) {
loop(fpath);
} else {
const mtimeObj = new Date(fstat.mtime);
if (mtimeObj > edgeTimeObj) {
output.push(`${fpath}: ${new Date(fstat.mtime).toLocaleString()}`);
}
}
});
}
};
loop(path.join(base, op));
fs.writeFileSync('./mtime.log', output.join('\n'), 'utf8');
console.log('Done.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment