index.js 426 B

123456789101112131415
  1. const { join, resolve } = require('path');
  2. const { readdirSync, statSync } = require('fs');
  3. module.exports = function list(dir, callback, pre='') {
  4. dir = resolve('.', dir);
  5. let arr = readdirSync(dir);
  6. let i=0, abs, stats;
  7. for (; i < arr.length; i++) {
  8. abs = join(dir, arr[i]);
  9. stats = statSync(abs);
  10. stats.isDirectory()
  11. ? list(abs, callback, join(pre, arr[i]))
  12. : callback(join(pre, arr[i]), abs, stats);
  13. }
  14. }