Skip to content

Instantly share code, notes, and snippets.

@Kirill255
Created July 16, 2019 19:09
Show Gist options
  • Save Kirill255/cc02f277c79cc3550c22ff830d99b529 to your computer and use it in GitHub Desktop.
Save Kirill255/cc02f277c79cc3550c22ff830d99b529 to your computer and use it in GitHub Desktop.
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!");
});
});
@Kirill255
Copy link
Author

Названия
text.txt

01-JavaScript Drum Kit
02-JS and CSS Clock
03-CSS Variables
04-Array Cardio Day 1
05-Flex Panel Gallery
06-Ajax Type Ahead
07-Array Cardio Day 2
08-Fun with HTML5 Canvas
09-Dev Tools Domination
10-Hold Shift and Check Checkboxes
11-Custom HTML5 Video Player
12-Key Sequence Detection
13-Slide in on Scroll
14-Object and Arrays - Reference VS Copy
15-LocalStorage and Event Delegation
16-CSS Text Shadow Mouse Move Effect
17-Sorting Band Names without articles
18-Adding Up Times with Reduce
19-Unreal Webcam Fun
20-Native Speech Recognition
21-Geolocation based Speedometer and Compass
22-Follow Along Link Highlighter
23-Speech Synthesis
24-Sticky Nav
25-Event Capture, Propagation, Bubbling and Once
26-Stripe Follow Along Nav
27-Click and Drag to Scroll
28-Video Speed Controller
29-Countdown Timer
30-Whack A Mole Game

Картинки
img/

small0.jpg
small1.jpg
small10.jpg
small11.jpg
small12.jpg
small13.jpg
small14.jpg
small15.jpg
small16.jpg
small17.jpg
small18.jpg
small19.jpg
small2.jpg
small20.jpg
small21.jpg
small22.jpg
small23.jpg
small24.jpg
small25.jpg
small26.jpg
small27.jpg
small28.jpg
small29.jpg
small3.jpg
small4.jpg
small5.jpg
small6.jpg
small7.jpg
small8.jpg
small9.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment