Phantomjs-maketree-method

提供:Dev Guides
移動先:案内検索

PhantomJS-makeTree

*makeTree* メソッドは、最終的なディレクトリを形成するために必要なすべてのフォルダーを作成します。 作成が成功した場合はtrue、それ以外の場合はfalseを返します。 ディレクトリが既に存在する場合、trueを返します。

構文

その構文は次のとおりです-

fs.makeTree(path);

次の例は、makeTreeメソッドの使用方法を示しています-

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();

上記のプログラムは、次の output を生成します。

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