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


稳定性: 1 - 实验性的

¥Stability: 1 - Experimental

  • src <string> | <URL> 要复制的源路径。

    ¥src <string> | <URL> source path to copy.

  • dest <string> | <URL> 要复制到的目标路径。

    ¥dest <string> | <URL> destination path to copy to.

  • options <Object>

    • dereference <boolean> 取消引用符号链接。默认值:false

      ¥dereference <boolean> dereference symlinks. Default: false.

    • errorOnExist <boolean>forcefalse 且目标存在时,抛出错误。默认值:false

      ¥errorOnExist <boolean> when force is false, and the destination exists, throw an error. Default: false.

    • filter <Function> 过滤复制文件/目录的函数。返回 true 则复制条目,返回 false 则忽略它。忽略目录时,其所有内容也将被跳过。还可以返回解析为 truefalse 默认值的 Promiseundefined

      ¥filter <Function> Function to filter copied files/directories. Return true to copy the item, false to ignore it. When ignoring a directory, all of its contents will be skipped as well. Can also return a Promise that resolves to true or false Default: undefined.

      • src <string> 要复制的源路径。

        ¥src <string> source path to copy.

      • dest <string> 要复制到的目标路径。

        ¥dest <string> destination path to copy to.

      • 返回:<boolean> | <Promise> 可强制转换为 boolean 的值或满足该值的 Promise

        ¥Returns: <boolean> | <Promise> A value that is coercible to boolean or a Promise that fulfils with such value.

    • force <boolean> 覆盖现有文件或目录。如果将此设置为 false 并且目标存在,则复制操作将忽略错误。使用 errorOnExist 选项更改此行为。默认值:true

      ¥force <boolean> overwrite existing file or directory. The copy operation will ignore errors if you set this to false and the destination exists. Use the errorOnExist option to change this behavior. Default: true.

    • mode <integer> 复制操作的修饰符。默认值:0。参见 fsPromises.copyFile()mode 标志。

      ¥mode <integer> modifiers for copy operation. Default: 0. See mode flag of fsPromises.copyFile().

    • preserveTimestamps <boolean> 当为 true 时,则 src 的时间戳将被保留。默认值:false

      ¥preserveTimestamps <boolean> When true timestamps from src will be preserved. Default: false.

    • recursive <boolean> 递归复制目录默认:false

      ¥recursive <boolean> copy directories recursively Default: false

    • verbatimSymlinks <boolean> 当为 true 时,则符号链接的路径解析将被跳过。默认值:false

      ¥verbatimSymlinks <boolean> When true, path resolution for symlinks will be skipped. Default: false

  • 返回:<Promise> 成功时将使用 undefined 履行。

    ¥Returns: <Promise> Fulfills with undefined upon success.

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

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

当将目录复制到另一个目录时,不支持 globs,并且行为类似于 cp dir1/ dir2/

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