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

133
Visualizações
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 à 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