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

168
Views
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 answers
Answer question

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 Report

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 Report
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!