UNPKG

1.09 kBMarkdownView Raw
1# move(src, dest, [options, callback])
2
3Moves a file or directory, even across devices.
4
5- `src` `<String>`
6- `dest` `<String>`
7- `options` `<Object>`
8 - `overwrite` `<boolean>`: overwrite existing file or directory, default is `false`.
9- `callback` `<Function>`
10
11## Example:
12
13```js
14const fs = require('fs-extra')
15
16const srcpath = '/tmp/file.txt'
17const dstpath = '/tmp/this/path/does/not/exist/file.txt'
18
19// With a callback:
20fs.move(srcpath, dstpath, err => {
21 if (err) return console.error(err)
22
23 console.log('success!')
24})
25
26// With Promises:
27fs.move(srcpath, dstpath)
28.then(() => {
29 console.log('success!')
30})
31.catch(err => {
32 console.error(err)
33})
34
35// With async/await:
36async function example (src, dest) {
37 try {
38 await fs.move(srcpath, dstpath)
39 console.log('success!')
40 } catch (err) {
41 console.error(err)
42 }
43}
44
45example(srcpath, dstpath)
46```
47
48**Using `overwrite` option**
49
50```js
51const fs = require('fs-extra')
52
53fs.move('/tmp/somedir', '/tmp/may/already/existed/somedir', { overwrite: true }, err => {
54 if (err) return console.error(err)
55
56 console.log('success!')
57})
58```