Phantomjs-copy-method

提供:Dev Guides
移動先:案内検索

PhantomJS-コピー

この方法は、ある場所から別の場所にファイルをコピーするのに役立ちます。 2つのパラメーターが必要です。 最初のパラメーターは source file で、2番目のパラメーターは file path で、コピーする必要があります。 ソースファイルまたは宛先ファイルが存在しない場合、エラーがスローされます。

構文

その構文は次のとおりです-

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

上記のプログラムは、次の 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));