Phantomjs-move-method
提供:Dev Guides
PhantomJS-移動
このメソッドは、指定されたファイルをあるパスから別のパスに移動します。 たとえば、 "move(source、destination)" 。 ここで、最初のパラメーターはソースファイルであり、2番目のパラメーターはファイル名を含む宛先パスです。 ソースファイルが見つからない場合、「宛先にファイルSOURCEをコピーできません」エラーがスローされ、実行がハングします。
宛先を作成できない場合、「宛先でファイルSOURCEをコピーできません」エラーがスローされ、実行がハングします。 既存のファイルは上書きされません。 ソースファイルを削除できない場合、「ファイルSOURCEを削除できません」エラーがスローされ、ハングします。
構文
その構文は次のとおりです-
fs.move(sourcefilepath, destinationfilepath)
例
*move* メソッドがどのように機能するかを理解するために例を見てみましょう。
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));
上記のプログラムは、次の output を生成します。
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