【问题标题】:I wonder if with (fs) I can copy a folder from one location to another我想知道是否使用(fs)我可以将文件夹从一个位置复制到另一个位置
【发布时间】:2020-12-26 09:57:50
【问题描述】:

有没有办法将文件夹从一个地方复制到另一个地方?

我用的方法:

fs.copyFileSync()

但是,它只复制文件。

有没有办法让我将文件夹从一个位置复制到另一个位置?

【问题讨论】:

  • 文件夹,有或没有子文件夹?无论哪种方式,您都需要编写一些实际代码
  • fs 模块本身不具备此功能。有许多 3rd 方模块提供像 fs-extra 这样的功能。
  • 我想将文件夹从桌面复制到另一个文件夹以防@jaromanda-x
  • 感谢@jfriend00,请注意!
  • 是的,在这种情况下你也需要编写代码

标签: javascript node.js fs


【解决方案1】:

你可以使用exec函数来执行一个os命令

const { exec } = require('child_process');
exec('cp -r <sorceFolderPath> <destFolderPath>', (err, stdout, stderr) => {
  }

这可能因操作系统而异

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    相关资源
    最近更新 更多