如何在node.js上移动文件? [英] How I move files on node.js?

查看:126
本文介绍了如何在node.js上移动文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在node.js上移动文件(如mv命令shell)?是否有任何方法或需要读取文件,写入新文件并删除旧文件?

How can I move files (like mv command shell) on node.js? Is there any method for that or I need to read a file, write to new file and remove older file?

推荐答案

根据seppo0010注释,我使用重命名功能来做到这一点。

According to seppo0010 comment, I used the rename function to do that.

http://nodejs.org/docs/latest/api/fs.html#fs_fs_rename_oldpath_newpath_callback


fs.rename(oldPath,newPath,callback)

fs.rename(oldPath, newPath, callback)

oldPath <String> | <Buffer>
newPath <String> | <Buffer>
callback <Function>

异步重命名(2)。没有任何可能的异常
的参数被赋予完成回调。

Asynchronous rename(2). No arguments other than a possible exception are given to the completion callback.

这篇关于如何在node.js上移动文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆