PhantomJS - 移動



此方法將指定的檔案從一個路徑移動到另一個路徑。例如,“move (source, destination)”。在此,第一個引數是原始檔,第二個引數是帶有檔名的目標路徑。如果找不到原始檔,則會丟擲“無法在 DESTINATION 處複製檔案 SOURCE”錯誤並掛起執行。

如果無法建立目標,則會丟擲“無法在 DESTINATION 處複製檔案 SOURCE”錯誤並掛起執行。它不會覆蓋現有檔案。如果無法刪除原始檔,則會丟擲“無法刪除檔案 SOURCE”錯誤並掛起。

語法

語法如下 −

fs.move(sourcefilepath, destinationfilepath) 

示例

讓我們舉例瞭解移動方法的工作原理。

var fs = require('fs'); 
var system = require('system'); 
var sourcefile = system.args[1]; 
var destfile = system.args[2]; 

console.log("Checking if sourcefile is a file : " +fs.isFile(sourcefile)); 
console.log("Checking if destfile is a file : " +fs.isFile(destfile)); 
console.log("moving the files"); 
fs.move("openmode.txt", "newfiles/move.txt"); 

console.log("Content from move.txt: "); 
console.log(fs.read("newfiles/move.txt")); 
console.log("Checking if sourcefile is a file : " +fs.isFile(sourcefile)); 

以上程式生成以下輸出

Checking if sourcefile is a file : true 
Checking if destfile is a file : false 
moving the files 
Content from move.txt: 
This is used for testing. 
Checking if sourcefile is a file : false 
phantomjs_file_system_module_methods.htm
廣告
© . All rights reserved.