2011-06-14 14:28:51 +04:00
|
|
|
// List all the files in a Tree of Directories
|
|
|
|
|
|
|
|
if (phantom.args.length !== 1) {
|
|
|
|
console.log("Usage: phantomjs scandir.js DIRECTORY_TO_SCAN");
|
|
|
|
phantom.exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
scanDirectory(phantom.args[0]);
|
2011-09-08 20:55:50 +04:00
|
|
|
phantom.exit();
|