![NPM](https://nodei.co/npm/mvdir.png)
![install size](https://packagephobia.now.sh/badge?p=mvdir@latest)
Why?
I did this: npm i mv
,
then I saw this: + mv@2.1.1 added 15 packages
,
then I said no.
It first tries fs.rename()
, then falls back on fs.copyFile()
and fs.unlink()
.
Usage:
const mvdir = require('mvdir');
await mvdir('source/file.js', 'dest/file.js');
await mvdir('source/file.js', 'dest/');
await mvdir('source', 'dest');
await mvdir('source', 'a/b/c/dest');
await mvdir('file.js', 'D:\\file.js');
const err = await mvdir('source/file.js', 'dest/file.js');
if (!err) console.log('done.');
mvdir('source/file.js', 'dest/file.js').then(err => {
if (!err) console.log('done.');
});
Copying:
await mvdir('file1.js', 'file2.js', { copy: true });
await mvdir('dir1', 'dir2', { copy: true });
Don't overwrite:
await mvdir('file1.js', 'file2.js', { overwrite: false });
await mvdir('dir1', 'dir2', { overwrite: false });