PhantomJS - makeTree



The makeTree method creates all the necessary folders to be able to form the final directories. This will return true, if the creation was successful, otherwise false. If the directory already exists, it will return true.

Syntax

Its syntax is as follows −

fs.makeTree(path);

Example

The following example shows how you can use the makeTree method −

var fs = require('fs'); 
var system = require('system'); 
var path = system.args[1]; 

fs.makeTree(path); 
console.log("Checking to see if the maketree has converted into directory : " +fs.isDirectory(path)); 
console.log("Listing the contents from the path given"); 

var a = path.split("/"); 
var list = fs.list(a[0]+"/"+a[1]+"/"+a[2]+"/"+a[3]); 

console.log(JSON.stringify(list)); 
phantom.exit();

The above program generates the following output.

Checking to see if the maketree has converted into directory : true 
Listing the contents from the path given 
[".","..","file.txt"]
phantomjs_file_system_module_methods.htm
Advertisements