如何在 node.js 中移动文件? [英] How do I move files in node.js?

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

问题描述

如何在 node.js 上移动文件(如 mv 命令外壳)?有什么方法可以解决这个问题,还是我应该读取文件,写入新文件并删除旧文件?

How can I move files (like mv command shell) on node.js? Is there any method for that or should I read a file, write to a 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天全站免登陆