scandir.js 633 B

123456789101112131415161718192021222324
  1. // List all the files in a Tree of Directories
  2. "use strict";
  3. var system = require('system');
  4. if (system.args.length !== 2) {
  5. console.log("Usage: phantomjs scandir.js DIRECTORY_TO_SCAN");
  6. phantom.exit(1);
  7. }
  8. var scanDirectory = function (path) {
  9. var fs = require('fs');
  10. if (fs.exists(path) && fs.isFile(path)) {
  11. console.log(path);
  12. } else if (fs.isDirectory(path)) {
  13. fs.list(path).forEach(function (e) {
  14. if ( e !== "." && e !== ".." ) { //< Avoid loops
  15. scanDirectory(path + '/' + e);
  16. }
  17. });
  18. }
  19. };
  20. scanDirectory(system.args[1]);
  21. phantom.exit();