- 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 - copy
This method helps to copy a file from one location to another. It takes two parameters. The first parameter is the source file and the second parameter is the file path, where it has to be copied. It will throw an error if the source or destination file does not exist.
Syntax
Its syntax is as follows −
var fs = require('fs'); fs.copy(sourcefile,destinationfile);
Example
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.isFile(path1)); console.log("Checking to see if destination is a file:" + fs.isFile(path2)); console.log("copying file from source to destination"); fs.copy(path1,path2); console.log("Checking to see if destination is a file:" + fs.isFile(path2)); console.log("contents from file are:"); console.log(fs.read(path2));
The above program generates the following output.
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.isFile(path1)); console.log("Checking to see if destination is a file:" + fs.isFile(path2)); console.log("copying file from source to destination"); fs.copy(path1,path2); console.log("Checking to see if destination is a file:" + fs.isFile(path2)); console.log("contents from file are:"); console.log(fs.read(path2));
phantomjs_file_system_module_methods.htm
Advertisements