scandir.js 618 B

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