- PhantomJS Tutorial
- PhantomJS - Home
- PhantomJS - Overview
- PhantomJS - Environment Setup
- PhantomJS - Object
- PhantomJS - Methods
- WebPage Module
- 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 - copyTree
The copyTree method will copy a directory from one path to another. The first parameter is the source folder and second parameter is the destination folder. If the destination does not exist, it will be created and every file and folder from the source folder will be copied to the destination folder.
Folders will be recursively copied, if any of the file or folder fails while copying, it will throw an error – "Unable to copy directory tree SOURCE at DESTINATION" and execution will hang.
Syntax
Its syntax is as follows −
copyTree(source,destination);
Example
The following example shows the use of copyTree method.
var fs = require('fs'); var system = require('system'); var path1 = system.args[1]; var path2 = system.args[2]; console.log("Checking to see if source is a file:" + fs.isDirectory(path1)); console.log("Checking to see if destination is a file:" + fs.isDirectory(path2)); console.log("copying tree directory from source to destination"); fs.copyTree(path1, path2); console.log("Checking to see if destination is a file:" + fs.isDirectory(path2));
The above program generates the following output.
Command − phantomjs copytree.js newdirectory/a/b/c/file.txt destfolder
Checking to see if source is a file:true Checking to see if destination is a file:false copying tree directory from source to destination Checking to see if destination is a file:true
phantomjs_file_system_module_methods.htm
Advertisements
To Continue Learning Please Login
Login with Google