Created
September 27, 2019 02:28
-
-
Save GUIEEN/9b6a82d96e3a1df7852a5687482efca0 to your computer and use it in GitHub Desktop.
changing multiple files' name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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