PhantomJS copy 复制文件


发布日期 : 2023-12-04 16:48:34 UTC

访问量: 10 次浏览

PhantomJS copy复制

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));