index.mjs 414 B

123456789101112131415
  1. import { join, resolve } from 'path';
  2. import { readdirSync, statSync } from 'fs';
  3. export default 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. }