- 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 - move
This method moves a specified file from one path to another. For example, "move (source, destination)". Here, the first parameter is the source file and the second parameter is the destination path with the file name. If the source file cannot be found, then it will throw an "Unable to copy file SOURCE at DESTINATION" error and hang execution.
If the destination cannot be created, then it will throw an "Unable to copy file SOURCE at DESTINATION" error and hang execution. It will not overwrite the existing files. If the source file cannot be deleted, then it will throw an ‘Unable to delete file SOURCE’ error and hang.
Syntax
Its syntax is as follows −
fs.move(sourcefilepath, destinationfilepath)
Example
Let us take an example to understand how the move method works.
var fs = require('fs'); var system = require('system'); var sourcefile = system.args[1]; var destfile = system.args[2]; console.log("Checking if sourcefile is a file : " +fs.isFile(sourcefile)); console.log("Checking if destfile is a file : " +fs.isFile(destfile)); console.log("moving the files"); fs.move("openmode.txt", "newfiles/move.txt"); console.log("Content from move.txt: "); console.log(fs.read("newfiles/move.txt")); console.log("Checking if sourcefile is a file : " +fs.isFile(sourcefile));
The above program generates the following output.
Checking if sourcefile is a file : true Checking if destfile is a file : false moving the files Content from move.txt: This is used for testing. Checking if sourcefile is a file : false