- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- 網路伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 其他
- 命令列介面
- PhantomJS - 螢幕捕獲
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用資源
- PhantomJS - 快速指南
- PhantomJS - 有用資源
- PhantomJS - 討論
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
廣告