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

132
Views
fs module does not rename a file

I have a function called normalize_string() that removes Brazilian characters from any string.

I need to remove all Brazilian characters from files and directories from a root directory that has several subdirectories and files.

I'm using the recursive-readdir package to list files recursively. Within recursive, when I try to use the Node.js fs.rename() method, the following error appears:

[Error: ENOENT: no such file or directory, rename '/home/caleb/Documents/test_rename/fólder/águia.txt' -> '/home/caleb/Documents/test_rename/folder/aguia.txt'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'rename',
  path: '/home/caleb/Documents/test_rename/fólder/águia.txt',
  dest: '/home/caleb/Documents/test_rename/folder/aguia.txt'
}

The main code currently looks like this:

const fs = require("fs")
const recursive = require("recursive-readdir");

const normalize_string = require("./normalize-string.js")

recursive("/home/caleb/Documents/test_rename", function (err, files) {
  for (const file of files) {
    const normalized = normalize_string(file)
    fs.rename(file, normalized, (error) => {
      console.error(error)
    })
  }
});

And the function to normalize a string is as follows:

module.exports = function normalize_string(str) {
  const removed_symbols = str.replace(/[!*\[\]{};:$@~`´,#%^&+=<>]/g, '')
  const normalized_string = removed_symbols.normalize("NFD").replace(/[\u0300-\u036f]/g, "")
  return normalized_string
}

It seems to me that the correct paths and the function of normalizing a string are being used as well, but this error intrigued me.

Any help is welcome. Thank you.

about 4 years ago · Juan Pablo Isaza
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!