Created
July 16, 2019 19:09
-
-
Save Kirill255/cc02f277c79cc3550c22ff830d99b529 to your computer and use it in GitHub Desktop.
This file contains 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 files = fs.readdirSync("./img"); | |
// console.log(files); | |
/* | |
[ | |
"small0.jpg", | |
"small1.jpg", | |
"small10.jpg", | |
... | |
] | |
*/ | |
const list = fs.readFileSync("text.txt", "utf8").split("\n"); | |
// console.log(list); | |
/* | |
[ | |
"01-JavaScript Drum Kit", | |
"02-JS and CSS Clock", | |
"03-CSS Variables", | |
... | |
] | |
*/ | |
files.forEach((file) => { | |
// console.log(file); | |
const [name, ext] = file.split("."); // ["small0", "jpg"] | |
const index = Number(name.replace(/\D+/gi, "")); // "small0" -> 0 | |
// console.log(list[index]); // "01-JavaScript Drum Kit" | |
// rename `./img/small0.jpg` -> `./newImg/01-JavaScript Drum Kit.jpg` | |
fs.rename(`./img/${file}`, `./newImg/${list[index]}.${ext}`, (err) => { | |
if (err) throw err; | |
console.log("Rename complete!"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Названия
text.txt
Картинки
img/