PhantomJS copy复制
此方法可以将文件从一个位置复制到另一个位置。它接受两个参数。第一个参数是 源文件 ,第二个参数是 文件路径 ,即要将文件复制到的位置。如果源文件或目标文件不存在,则会抛出错误。
语法
其语法如下所示−
var fs = require('fs');
fs.copy(sourcefile,destinationfile);
示例
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));
以上程序生成以下 输出 。
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));