Note: When src
is a file, dest
must be a file and when src
is a directory, dest
must be a directory.
Optional
options: MoveOptionsimport * as fs from 'fs-extra'
const src = '/tmp/file.txt'
const dest = '/tmp/this/path/does/not/exist/file.txt'
// With a callback:
fs.move(src, dest, err => {
if (err) return console.error(err)
console.log('success!')
})
// With Promises:
fs.move(src, dest)
.then(() => {
console.log('success!')
})
.catch(err => {
console.error(err)
})
// With async/await:
async function asyncAwait () {
try {
await fs.move(src, dest)
console.log('success!')
} catch (err) {
console.error(err)
}
}
asyncAwait()
// Using `overwrite` option
fs.move('/tmp/somedir', '/tmp/may/already/exist/somedir', { overwrite: true }, err => {
if (err) return console.error(err)
console.log('success!')
})
Generated using TypeDoc
Moves a file or directory, even across devices.