PhantomJS makeTree 使用方法


发布日期 : 2020-04-02 23:32:11 UTC

访问量: 10 次浏览

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

上述程序生成以下
输出

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