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

134
Vistas
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
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