Si el nombre del fichero es «ya» renombrarlo a «ya.txt»
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
const ficheros = require('fs'); ficheros.readdir("./", (err, files) => { files.forEach(file => { if(file.toLowerCase() === "ya") { cambiarnombre = 'ya.txt'; ficheros.rename(file, file.replace(file,cambiarnombre), (err) => { if (err) throw err; console.log('Nombre cambiado correctamente'); }); } }); }); |
Resultado
