Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda