Skip to content

Instantly share code, notes, and snippets.

@GUIEEN
Created September 27, 2019 02:28
Show Gist options
  • Select an option

  • Save GUIEEN/9b6a82d96e3a1df7852a5687482efca0 to your computer and use it in GitHub Desktop.

Select an option

Save GUIEEN/9b6a82d96e3a1df7852a5687482efca0 to your computer and use it in GitHub Desktop.
changing multiple files' name
const fs = require('fs');
const path = require('path');
fs.readdir('./icons', (err, files) => {
if (err) {
return;
}
for (const file of files) {
console.log(file);
// console.log(__dirname);
const target = path.join(__dirname, `icons/${file}`);
const newPath = path.join(__dirname, `icons/Category${file}`);
fs.rename(target, newPath, err => {
if (err) {
console.log(err);
throw err;
}
console.log('Renaming', file, 'to', `Category${file}`);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment