PhantomJS - copyTree 方法
copyTree 方法将目录从一个路径复制到另一个路径。第一个参数是 源 文件夹,第二个参数是 目标 文件夹。如果目标不存在,则将创建目标并将源文件夹中的每个文件和文件夹复制到目标文件夹。
文件夹将递归复制,如果复制过程中任何文件或文件夹失败,将抛出错误 - "无法在目标处复制目录树 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 目标文件夹
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.html