Phantomjs-copytree-method

提供:Dev Guides
移動先:案内検索

PhantomJS-copyTree

copyTreeメソッドは、あるパスから別のパスにディレクトリをコピーします。 最初のパラメーターは source フォルダーで、2番目のパラメーターは destination フォルダーです。 宛先が存在しない場合は、宛先が作成され、ソースフォルダーのすべてのファイルとフォルダーが宛先フォルダーにコピーされます。

フォルダーは再帰的にコピーされます。コピー中にファイルまたはフォルダーのいずれかが失敗すると、「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));

上記のプログラムは、次の output を生成します。

コマンド-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