Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda