节点fs复制文件夹 [英] Node fs copy a folder

查看:216
本文介绍了节点fs复制文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用节点fs模块复制文件夹.我熟悉readFileSync()writeFileSync()方法,但是我想知道应该使用哪种方法来复制指定的文件夹?

I am trying to copy a folder using Node fs module. I am familiar with readFileSync() and writeFileSync() methods but I am wondering what method I should use to copy a specified folder?

推荐答案

您可以使用 fs-extra 像这样将一个文件夹的内容复制到另一个文件夹

You can use fs-extra to copy contents of one folder to another like this

var fs = require("fs-extra");

fs.copy('/path/to/source', '/path/to/destination', function (err) {
  if (err) return console.error(err)
  console.log('success!')
});

还有一个同步版本.

这篇关于节点fs复制文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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