Update rename-to-lowercase.js

This commit is contained in:
William Harrison
2024-11-09 20:43:57 +08:00
parent 1eedc437a6
commit f33e2f4f46
+7 -5
View File
@@ -3,21 +3,21 @@ const path = require("path");
const directoryPath = path.join(__dirname, "../domains");
(async () => {
function renameFilesToLowercase() {
// Read the files in the 'domains' directory
fs.readdirSync(directoryPath, (err, files) => {
fs.readdir(directoryPath, (err, files) => {
if (err) {
console.error("Error reading directory:", err);
return;
}
files.forEach(async (file) => {
files.forEach((file) => {
const oldPath = path.join(directoryPath, file);
const newPath = path.join(directoryPath, file.toLowerCase());
// Only rename if the file name is not already in lowercase
if (oldPath !== newPath) {
fs.renameSync(oldPath, newPath, (err) => {
fs.rename(oldPath, newPath, (err) => {
if (err) {
console.error("Error renaming file:", err);
} else {
@@ -27,4 +27,6 @@ const directoryPath = path.join(__dirname, "../domains");
}
});
});
})();
}
renameFilesToLowercase();