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"]
phantomjs_file_system_module_methods.htm
廣告
© . All rights reserved.