- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- Web 伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 其他
- 命令列介面
- PhantomJS - 截圖
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用資源
- PhantomJS - 快速指南
- PhantomJS - 有用資源
- PhantomJS - 討論
PhantomJS - copyTree
copyTree 方法會將一個目錄從一個路徑複製到另一個路徑。第一個引數是源資料夾,第二個引數是目標資料夾。如果目標資料夾不存在,它會建立目標資料夾,並且原始檔夾中的每個檔案和資料夾都會複製到目標資料夾中。
資料夾會遞迴複製,如果在複製過程中有任何檔案或資料夾失敗,它將丟擲錯誤 – “無法在 DESTINATION複製目錄樹 SOURCE”並且執行會暫停。
語法
它的語法如下 −
copyTree(source,destination);
示例
以下示例顯示了 copyTree 方法的使用。
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.isDirectory(path1));
console.log("Checking to see if destination is a file:" + fs.isDirectory(path2));
console.log("copying tree directory from source to destination");
fs.copyTree(path1, path2);
console.log("Checking to see if destination is a file:" + fs.isDirectory(path2));
上述程式生成以下輸出。
命令 − phantomjs copytree.js newdirectory/a/b/c/file.txt destfolder
Checking to see if source is a file:true Checking to see if destination is a file:false copying tree directory from source to destination Checking to see if destination is a file:true
phantomjs_file_system_module_methods.htm
廣告