Phantomjs-removetree-method

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

PhantomJS-removeTree

removeTreeメソッドは、指定されたフォルダーからすべてのファイルとフォルダーを削除し、最終的にフォルダー自体を削除するために使用されます。 このプロセスの実行中にエラーが発生した場合、「ディレクトリツリーPATHを削除できません」というエラーが発生し、実行がハングします。

構文

その構文は次のとおりです-

fs.removeTree(foldertodelete)

次の例は、 removeTree メソッドの動作を示しています。

var fs = require('fs');
var system = require('system');
var path = system.args[1];
console.log("Directory present : "+fs.isDirectory(path));

var a = fs.list(path);
console.log("Listing the contents from the directory : " + JSON.stringify(a));
console.log("Removing directory "+path);

var rd = fs.removeTree(path);
console.log("Directory present "+fs.isDirectory(path));
phantom.exit();

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

Directory present : true
Listing the contents from the directory : [".","..","examples","newfiles"]
Removing directory removetree
Directory present false