PhantomJS - move 方法
此方法将指定的文件从一个路径移动到另一个路径。例如,"move (source, destination)"。这里,第一个参数是源文件,第二个参数是带有文件名的目标路径。如果找不到源文件,则会抛出"无法在目标处复制文件 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));
上述程序生成以下输出。
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.html