2011-06-14 14:28:51 +04:00
|
|
|
// List all the files in a Tree of Directories
|
2015-04-10 10:51:00 +03:00
|
|
|
|
|
|
|
"use strict";
|
2012-01-14 19:13:26 +04:00
|
|
|
var system = require('system');
|
2011-06-14 14:28:51 +04:00
|
|
|
|
2012-01-14 19:13:26 +04:00
|
|
|
if (system.args.length !== 2) {
|
2011-06-14 14:28:51 +04:00
|
|
|
console.log("Usage: phantomjs scandir.js DIRECTORY_TO_SCAN");
|
2012-05-16 11:37:26 +04:00
|
|
|
phantom.exit(1);
|
2011-06-14 14:28:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var scanDirectory = function (path) {
|
2011-09-08 20:55:50 +04:00
|
|
|
var fs = require('fs');
|
2011-08-05 01:00:18 +04:00
|
|
|
if (fs.exists(path) && fs.isFile(path)) {
|
2011-06-14 14:28:51 +04:00
|
|
|
console.log(path);
|
2011-08-05 01:00:18 +04:00
|
|
|
} else if (fs.isDirectory(path)) {
|
|
|
|
fs.list(path).forEach(function (e) {
|
2011-06-14 14:28:51 +04:00
|
|
|
if ( e !== "." && e !== ".." ) { //< Avoid loops
|
|
|
|
scanDirectory(path + '/' + e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2012-01-14 19:13:26 +04:00
|
|
|
scanDirectory(system.args[1]);
|
2011-09-08 20:55:50 +04:00
|
|
|
phantom.exit();
|