PhantomJS - 複製



此方法有助於將檔案從一個位置複製到另一個位置。它有兩個引數。第一個引數是原始檔,第二個引數是檔案路徑,必須將檔案複製到該路徑。如果原始檔或目標檔案不存在,它會丟擲錯誤。

語法

其語法如下 -

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)); 
phantomjs_file_system_module_methods.htm
廣告
© . All rights reserved.