-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename.js
32 lines (30 loc) · 923 Bytes
/
rename.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");
fs.readdir(__dirname, { withFileTypes: true }, (err, filenames) => {
filenames.forEach((f) => {
if (f.name.endsWith(".json")) {
fs.readFile(__dirname + "/" + f.name, "utf-8", (err, content) => {
if (err) {
console.log("Error reading file from disk:", err);
return;
}
const jsonFile = JSON.parse(content);
if (jsonFile.objects) {
const code = f.name.slice(0, 3);
if (jsonFile.objects[code]) {
jsonFile.objects[code].geometries.forEach((g) => {
if (g.properties.id) {
const id = g.properties.id;
g["id"] = id;
fs.writeFile(
__dirname + "/" + f.name,
JSON.stringify(jsonFile),
(e) => {}
);
}
});
}
}
});
}
});
});