* Moves a path. * * @param source source path * @param dest destination path * @param options optional. See MoveOptions.
(source, dest, options = {})
| 3404 | * @param options optional. See MoveOptions. |
| 3405 | */ |
| 3406 | function mv(source, dest, options = {}) { |
| 3407 | return __awaiter(this, void 0, void 0, function* () { |
| 3408 | if (yield ioUtil.exists(dest)) { |
| 3409 | let destExists = true; |
| 3410 | if (yield ioUtil.isDirectory(dest)) { |
| 3411 | // If dest is directory copy src into dest |
| 3412 | dest = path.join(dest, path.basename(source)); |
| 3413 | destExists = yield ioUtil.exists(dest); |
| 3414 | } |
| 3415 | if (destExists) { |
| 3416 | if (options.force == null || options.force) { |
| 3417 | yield rmRF(dest); |
| 3418 | } |
| 3419 | else { |
| 3420 | throw new Error('Destination already exists'); |
| 3421 | } |
| 3422 | } |
| 3423 | } |
| 3424 | yield mkdirP(path.dirname(dest)); |
| 3425 | yield ioUtil.rename(source, dest); |
| 3426 | }); |
| 3427 | } |
| 3428 | exports.mv = mv; |
| 3429 | /** |
| 3430 | * Remove a path recursively with force |