PhantomJS - removeTree



removeTree 方法用於刪除給定資料夾中的所有檔案和資料夾,最後刪除資料夾本身。如果執行此過程時出現任何錯誤,它會丟擲以下錯誤 -“無法刪除目錄樹 PATH”並掛起執行。

語法

其語法如下 –

fs.removeTree(foldertodelete) 

示例

以下示例顯示了 **removeTree** 方法如何工作。

var fs = require('fs'); 
var system = require('system'); 
var path = system.args[1]; 
console.log("Directory present : "+fs.isDirectory(path)); 

var a = fs.list(path); 
console.log("Listing the contents from the directory : " + JSON.stringify(a)); 
console.log("Removing directory "+path);  

var rd = fs.removeTree(path); 
console.log("Directory present "+fs.isDirectory(path)); 
phantom.exit();

上述程式產生了以下 **輸出**。

Directory present : true 
Listing the contents from the directory : [".","..","examples","newfiles"] 
Removing directory removetree 
Directory present false
phantomjs_file_system_module_methods.htm
廣告
© . All rights reserved.