PhantomJS 文件系统 removeTree 用法与示例


发布日期 : 2023-12-31 08:45:53 UTC

访问量: 9 次浏览

PhantomJS removeTree

removeTree方法用于删除给定文件夹中的所有文件和文件夹,最后删除该文件夹本身。如果在执行此过程中出现任何错误,它将抛出一个错误-“无法删除目录树路径”并挂起执行。

语法

它的语法如下所示 –

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