Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
Moving directories with subdirectories using `moveSync` from `fs-extra`

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.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!