PhantomJS - removeTree
The removeTree method is used to delete all the files and folders from a given folder and finally delete the folder itself. If there is any error while doing this process, it will throw an error "Unable to remove directory tree PATH" and hang execution.
Syntax
Its syntax is as follows −
fs.removeTree(foldertodelete)
Example
The following example shows how the removeTree method works.
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();
The above program generates the following output.
Directory present : true Listing the contents from the directory : [".","..","examples","newfiles"] Removing directory removetree Directory present false
phantomjs_file_system_module_methods.htm
Advertisements