[6a3a178] | 1 | # @npmcli/move-file
|
---|
| 2 |
|
---|
| 3 | A fork of [move-file](https://github.com/sindresorhus/move-file) with
|
---|
| 4 | compatibility with all node 10.x versions.
|
---|
| 5 |
|
---|
| 6 | > Move a file (or directory)
|
---|
| 7 |
|
---|
| 8 | The built-in
|
---|
| 9 | [`fs.rename()`](https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback)
|
---|
| 10 | is just a JavaScript wrapper for the C `rename(2)` function, which doesn't
|
---|
| 11 | support moving files across partitions or devices. This module is what you
|
---|
| 12 | would have expected `fs.rename()` to be.
|
---|
| 13 |
|
---|
| 14 | ## Highlights
|
---|
| 15 |
|
---|
| 16 | - Promise API.
|
---|
| 17 | - Supports moving a file across partitions and devices.
|
---|
| 18 | - Optionally prevent overwriting an existing file.
|
---|
| 19 | - Creates non-existent destination directories for you.
|
---|
| 20 | - Support for Node versions that lack built-in recursive `fs.mkdir()`
|
---|
| 21 | - Automatically recurses when source is a directory.
|
---|
| 22 |
|
---|
| 23 | ## Install
|
---|
| 24 |
|
---|
| 25 | ```
|
---|
| 26 | $ npm install @npmcli/move-file
|
---|
| 27 | ```
|
---|
| 28 |
|
---|
| 29 | ## Usage
|
---|
| 30 |
|
---|
| 31 | ```js
|
---|
| 32 | const moveFile = require('@npmcli/move-file');
|
---|
| 33 |
|
---|
| 34 | (async () => {
|
---|
| 35 | await moveFile('source/unicorn.png', 'destination/unicorn.png');
|
---|
| 36 | console.log('The file has been moved');
|
---|
| 37 | })();
|
---|
| 38 | ```
|
---|
| 39 |
|
---|
| 40 | ## API
|
---|
| 41 |
|
---|
| 42 | ### moveFile(source, destination, options?)
|
---|
| 43 |
|
---|
| 44 | Returns a `Promise` that resolves when the file has been moved.
|
---|
| 45 |
|
---|
| 46 | ### moveFile.sync(source, destination, options?)
|
---|
| 47 |
|
---|
| 48 | #### source
|
---|
| 49 |
|
---|
| 50 | Type: `string`
|
---|
| 51 |
|
---|
| 52 | File, or directory, you want to move.
|
---|
| 53 |
|
---|
| 54 | #### destination
|
---|
| 55 |
|
---|
| 56 | Type: `string`
|
---|
| 57 |
|
---|
| 58 | Where you want the file or directory moved.
|
---|
| 59 |
|
---|
| 60 | #### options
|
---|
| 61 |
|
---|
| 62 | Type: `object`
|
---|
| 63 |
|
---|
| 64 | ##### overwrite
|
---|
| 65 |
|
---|
| 66 | Type: `boolean`\
|
---|
| 67 | Default: `true`
|
---|
| 68 |
|
---|
| 69 | Overwrite existing destination file(s).
|
---|