-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (29 loc) · 961 Bytes
/
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
const fs = require('fs');
const path = require('path');
const replaceThis = 1;
const replaceWith = 'harshal';
const preview = false;
const folder = __dirname;
try {
fs.readdir(folder, (err, data) => {
// console.log(data);
for (index in data) {
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, () => {
console.log("Rename Success", item, newFile);
})
}
else {
//if file didn't have same name means replacethis=replaceWith are different
if ("data/" + item != newFile) {
console.log("data/" + item + "will be rename to " + newFile);
}
}
}
});
} catch (err) {
console.error(err);
}