fsPromises.cp(src, dest[, options])


  • src <string> | <URL> 要复制的源路径。
  • dest <string> | <URL> 要复制到的目标路径。
  • options <Object>
    • dereference <boolean> 取消引用符号链接。默认值: false
    • errorOnExist <boolean>forcefalse 且目标存在时,抛出错误。默认值:false
    • filter <Function> 用于过滤复制的文件/目录的函数。返回 true 表示复制该项目,返回 false 表示忽略它。忽略目录时,其所有内容也将被跳过。还可以返回一个 Promise,其解析结果为 truefalse默认值: undefined
      • src <string> 要复制的源路径。
      • dest <string> 要复制到的目标路径。
      • 返回:<boolean> | <Promise> 一个可以强制转换为 boolean 的值,或者一个符合该值的 Promise
    • force <boolean> 覆盖已有的文件或目录。如果将此设置为 false 并且目标已存在,复制操作将忽略错误。使用 errorOnExist 选项可以更改此行为。默认值: true
    • mode <integer> 复制操作的修饰符。默认值: 0。请参见 fsPromises.copyFile()mode 标志。
    • preserveTimestamps <boolean>true 时间戳来自 src 时将被保留。默认值: false
    • recursive <boolean> 递归复制目录 默认值: false
    • verbatimSymlinks <boolean>true 时,将跳过符号链接的路径解析。默认值: false
  • 返回:<Promise> 成功后用 undefined 完成。

异步地将整个目录结构从 src 复制到 dest,包括子目录和文件。

🌐 Asynchronously copies the entire directory structure from src to dest, including subdirectories and files.

将目录复制到另一个目录时,不支持通配符,行为类似于 cp dir1/ dir2/

🌐 When copying a directory to another directory, globs are not supported and behavior is similar to cp dir1/ dir2/.