Zmień nazwę plików w katalogu z Node.js
const fs = require("fs");
const path = require("path");
const folderPath = "./assets";
// read all files in the directory
let filesArr = fs.readdirSync(folderPath);
// Loop through array and rename all files
filesArr.forEach((file, index) => {
let fullPath = path.join(folderPath, file);
let fileExtension = path.extname(file);
let fileName = path.basename(file, fileExtension);
let newFileName = fileName + index + "." + fileExtension;
try {
fs.renameSync(fullPath, path.join(folderPath, newFileName));
} catch (error) {
console.error(error)
}
});
Puzzled Porcupine