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

169
Vistas
fs.rename unable to rename directories with contents on Windows 10

So I've seen several questions similar to this issue but I haven't found anything that quite fixes it.

I'm able to rename a directory with node.js as long as the directory is empty. Once I add contents, I get the error: EPERM: operation not permitted. If I delete the contents, I regain the ability to rename. Is there something simple I'm missing here? Nothing crazy in the code... just can't rename a directory if it has contents.

app.post('/rename', function(req, res, next) {
    let _target = req.body.target,
        _from = req.body.from,
        _to = req.body.to;
    
    fs.renameSync(
        'public/' + _target + '/' + _from,
        'public/' + _target + '/' + _to,
        function(err, data) {
            if (err) { sLog(err); return }
            res.send('File Renamed');
        }
    );
});

-- EDIT --

The issue is when the directory has sub directories. Files in the directory to rename don't seem to affect the action

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The issue is that I was using nodemon instead of node. Apparently, as a listener, it was locking the files... once I ran everything as node, it functioned as expected.

about 4 years ago · Juan Pablo Isaza Denunciar

0

fs.renameSync doesn't work when the folder is not empty, so you should use another way just like the following:

import fsExtra from "fs-extra";

//then copy and delete, disgusting but work
fsExtra.copySync(oldpath, path);
fsExtra.rmdirSync(oldpath, { recursive: true });
about 4 years ago · Juan Pablo Isaza Denunciar
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