Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

copy-sync.md 1.4 KiB

3 lat temu
12345678910111213141516171819202122232425262728293031323334353637
  1. # copySync(src, dest, [options])
  2. Copy a file or directory. The directory can have contents. Like `cp -r`.
  3. - `src` `<String>`
  4. - `dest` `<String>`
  5. - `options` `<Object>`
  6. - `overwrite` `<boolean>`: overwrite existing file or directory, default is `true`. _Note that the copy operation will silently fail if you set this to `false` and the destination exists._ Use the `errorOnExist` option to change this behavior.
  7. - `errorOnExist` `<boolean>`: when `overwrite` is `false` and the destination exists, throw an error. Default is `false`.
  8. - `dereference` `<boolean>`: dereference symlinks, default is `false`.
  9. - `preserveTimestamps` `<boolean>`: will set last modification and access times to the ones of the original source files, default is `false`.
  10. - `filter` `<Function>`: Function to filter copied files. Return `true` to include, `false` to exclude. This can also be a RegExp, however this is deprecated (See [issue #239](https://github.com/jprichardson/node-fs-extra/issues/239) for background).
  11. ## Example:
  12. ```js
  13. const fs = require('fs-extra')
  14. // copy file
  15. fs.copySync('/tmp/myfile', '/tmp/mynewfile')
  16. // copy directory, even if it has subdirectories or files
  17. fs.copySync('/tmp/mydir', '/tmp/mynewdir')
  18. ```
  19. **Using filter function**
  20. ```js
  21. const fs = require('fs-extra')
  22. const filterFunc = (src, dest) => {
  23. // your logic here
  24. // it will be copied if return true
  25. }
  26. fs.copySync('/tmp/mydir', '/tmp/mynewdir', { filter: filterFunc })
  27. ```