Skip to content

Commit

Permalink
copy()
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim committed Jan 2, 2017
1 parent de3055e commit c3109ea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
36 changes: 1 addition & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ try {

Methods
-------
- [copy](#copy)
- [copy](docs/copy.md)
- [copySync](#copy)
- [emptyDir](#emptydirdir-callback)
- [emptyDirSync](#emptydirdir-callback)
Expand Down Expand Up @@ -116,40 +116,6 @@ Methods

**NOTE:** You can still use the native Node.js methods. They are copied over to `fs-extra`.


### copy()

**copy(src, dest, [options], callback)**


Copy a file or directory. The directory can have contents. Like `cp -r`.

Options:
- 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.
- errorOnExist (boolean): when `overwrite` is `false` and the destination exists, throw an error. Default is `false`.
- dereference (boolean): dereference symlinks, default is `false`.
- preserveTimestamps (boolean): will set last modification and access times to the ones of the original source files, default is `false`.
- filter: 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). _Warning: `copySync` currently applies the filter only to files (see [#180](https://github.com/jprichardson/node-fs-extra/issues/180)). This will be fixed in a future release._

Sync: `copySync()`

Example:

```js
var fs = require('fs-extra')

fs.copy('/tmp/myfile', '/tmp/mynewfile', function (err) {
if (err) return console.error(err)
console.log("success!")
}) // copies file

fs.copy('/tmp/mydir', '/tmp/mynewdir', function (err) {
if (err) return console.error(err)
console.log('success!')
}) // copies directory, even if it has subdirectories or files
```


### emptyDir(dir, [callback])

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted.
Expand Down
31 changes: 31 additions & 0 deletions docs/copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# copy()

**copy(src, dest, [options], callback)**


Copy a file or directory. The directory can have contents. Like `cp -r`.

## Options:
- 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.
- errorOnExist (boolean): when `overwrite` is `false` and the destination exists, throw an error. Default is `false`.
- dereference (boolean): dereference symlinks, default is `false`.
- preserveTimestamps (boolean): will set last modification and access times to the ones of the original source files, default is `false`.
- filter: 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).

Sync: `copySync()`

## Example:

```js
var fs = require('fs-extra')

fs.copy('/tmp/myfile', '/tmp/mynewfile', function (err) {
if (err) return console.error(err)
console.log("success!")
}) // copies file

fs.copy('/tmp/mydir', '/tmp/mynewdir', function (err) {
if (err) return console.error(err)
console.log('success!')
}) // copies directory, even if it has subdirectories or files
```

0 comments on commit c3109ea

Please sign in to comment.