PhantomJS - removeTree 方法

removeTree 方法用于从给定文件夹中删除所有文件和文件夹,并最终删除文件夹本身。如果在执行此过程时出现任何错误,它将抛出错误 - "无法删除目录树 PATH"并挂起执行。

语法

其语法如下 −

fs.removeTree(folderdelete)

示例

以下示例显示了 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.html