-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (30 loc) · 1008 Bytes
/
script.js
File metadata and controls
35 lines (30 loc) · 1008 Bytes
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 directoryPath = path.join(__dirname, 'src/appointment');
function renameFilesInDirectory(dir) {
fs.readdir(dir, (err, files) => {
if (err) {
return console.error(`Unable to scan directory: ${err}`);
}
files.forEach(file => {
const filePath = path.join(dir, file);
if (fs.statSync(filePath).isDirectory()) {
// Recursively rename files in subdirectories
renameFilesInDirectory(filePath);
} else {
const newFileName = file.replace(/service/g, 'appointment');
if (newFileName !== file) {
const newFilePath = path.join(dir, newFileName);
fs.rename(filePath, newFilePath, (err) => {
if (err) {
console.error(`Error renaming file: ${err}`);
} else {
console.log(`Renamed: ${filePath} -> ${newFilePath}`);
}
});
}
}
});
});
}
renameFilesInDirectory(directoryPath);