I'm trying to replace the parent directory of a given path
src/path/to/file.ext
=> dest/path/to/file.newext
My current solution involves using string.split
, and looks pretty awful. It works, though.
var path = require('path');
var outDir = 'dest/'
var inFile = 'src/path/to/file.ext'
var outFile = path.basename(inFile, path.extname(inFile)) + '.newext';
var destDir = path.join(outDir, path.dirname(inFile.split('/').slice(1).join('/')));
outFile = path.join(destDir, outFile) // dest/path/to/file.newext
Is there another way I could go about this?