-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (39 loc) · 1.09 KB
/
index.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
33
34
35
36
37
38
39
40
41
42
43
44
const fs = require('node:fs');
const path = require('path');
const replaceThis = "prithvi";
const replaceWith = "ritzz";
const preview = false;
const folder = __dirname;
try {
fs.readdir(folder, (err, data) => {
if (err) {
console.error("Error reading directory:", err);
return;
}
// Check if data is undefined or null
if (!data) {
console.error("No files found in the directory.");
return;
}
for (let index = 0; index < data.length; index++) {
const item = data[index];
let oldFile = path.join(folder, item);
let newFile = path.join(folder, item.replaceAll(replaceThis, replaceWith));
if (!preview) {
fs.rename(oldFile, newFile, (err) => {
if (err) {
console.error("Error renaming file:", err);
} else {
console.log("Rename success:", oldFile, "->", newFile);
}
});
} else {
if (oldFile !== newFile) {
console.log(oldFile + " will be renamed to " + newFile);
}
}
}
});
} catch (err) {
console.error(err);
}