BlueGit

blue-star danique-bot

Files

danique-bot / node_modules / phantomjs-prebuilt / lib / phantom / examples / scandir.js

scandir.js

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