I have 2 paths:
app/consultants/pages/assignments
app/consultants/pages/consultants
Both paths contain subdirectories and files.
I created a reduce function that returns an array of objects with the following structure:
[{
model: 'consultants',
subModel: 'assignments',
path: '/app/consultants/pages/assignments'
}
{
model: 'consultants',
path: '/app/consultants/pages/consultants'
}]
Then I loop through this array and try to move the directory and all its directories and files:
getAllPagesDirs(appDir).forEach((pages, index) => {
if (pages.subModel) {
fs.moveSync(pages.path, path.join(path.resolve("pages"), pages.model, pages.subModel))
} else {
fs.moveSync(pages.path, path.join(path.resolve("pages"), pages.model))
}
})
I'm trying to move the directories to the following with all its files:
/pages/consultants/[consultantSubdirectory]
&
/pages/consultants/assignments/[assignmentsSubdirectory]
What's currently happening:
I get an error: dest already exists. And only the assignments sub directory gets moved.
Edit: I'm using fs-extra, but have no issue with using node's fs module.