move-unused-path
v2.0.2
Published
Reliably move to an unused path.
Readme
Move Unused Path
Reliably move to an unused path.
It is basically a wrapper around get-unused-path which doesn't just return an unused path, but also moves to it.
Install
npm install move-unused-pathUsage
import fs from 'fs';
import moveUnusedPath from 'move-unused-path';
// Let's move a file to an unused path
const sourceFilePath = '/x/y/z/bar.txt';
const result = await moveUnusedPath ( sourceFilePath, {
fileName: 'foo.txt',
folderPath: '/x/y/z',
// incrementer: ( name, ext, attempt ) => attempt > 1 ? `${name}-${attempt}${ext}` : `${name}${ext}`,
// maxTries: 1_000
});
result.folderPath; // => '/x/y/z'
result.filePath; // => '/x/y/z/foo (3).txt'
result.fileName; // => 'foo (3).txt'
// Let's check that the file got actually moved
console.log ( fs.existsSync ( sourceFilePath ) ); // => false
console.log ( fs.existsSync ( result.filePath ) ); // => trueRelated
- unused-path: Reliably get an unused path and copy/move/write to it.
- copy-unused-path: Reliably copy to an unused path.
- get-unused-path: Reliably get an unused path you can write to.
- write-unused-path: Reliably write to an unused path.
License
MIT © Fabio Spampinato
