fs.cp(src, dest[, options], callback)


稳定性: 1 - 实验性

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

异步地将整个目录结构从 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/.】