-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename_slug.js
32 lines (27 loc) · 1.08 KB
/
rename_slug.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs');
const path = require('path');
const slug = require('unique-slug');
function renameGifsWithSlug(folderPath) {
function traverseDirectory(dirPath) {
const files = fs.readdirSync(dirPath);
files.forEach(file => {
const filePath = path.join(dirPath, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
traverseDirectory(filePath);
} else {
if (path.extname(filePath).toLowerCase() === '.gif') {
const fileSlug = slug(path.parse(file).name);
const newFileName = `${fileSlug}.gif`;
const newPath = path.join(dirPath, newFileName);
fs.renameSync(filePath, newPath);
console.log(`Renamed ${file} to ${newFileName}`);
}
}
});
}
traverseDirectory(folderPath);
}
const folderPath = 'ALL'; // Replace this with the path to your folder
renameGifsWithSlug(folderPath);
console.log('GIF files have been renamed with unique slugs.');