
- PhantomJS - Home
- PhantomJS - Overview
- PhantomJS - Environment Setup
- PhantomJS - Object
- PhantomJS - Methods
- PhantomJS - Properties
- PhantomJS - Methods
- PhantomJS - Events/Callbacks
- PhantomJS - Child Process Module
- File System Module
- PhantomJS - Properties
- PhantomJS - Methods
- System Module
- PhantomJS - Properties
- Web Server Module
- PhantomJS - Properties
- PhantomJS - Methods
- Miscellaneous
- Command Line Interface
- PhantomJS - Screen Capture
- PhantomJS - Page Automation
- PhantomJS - Network Monitoring
- PhantomJS - Testing
- PhantomJS - REPL
- PhantomJS - Examples
- PhantomJS Useful Resources
- PhantomJS - Quick Guide
- PhantomJS - Useful Resources
- PhantomJS - Discussion
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