This will try to delete the specified folder.
The directory needs to be empty to be removed with this method. To delete an non empty folder, fs.removeTree should be used.
When errors occur during a call, it will throw a ‘Unable to remove directory PATH’ and hang execution.
var fs = require('fs'); var toDelete = 'someFolder'; // Test if the folder is empty before deleting it if(fs.list(toDelete).length === 0) fs.removeDirectory(toDelete); phantom.exit();