34 lines
880 B
JavaScript
34 lines
880 B
JavaScript
|
import fs from "fs";
|
||
|
import path from "path";
|
||
|
|
||
|
const convertSnakeToKebabCase = (directoryPath) => {
|
||
|
fs.readdir(directoryPath, (err, files) => {
|
||
|
if (err) {
|
||
|
console.error("Error reading directory:", err);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
files.forEach((file) => {
|
||
|
const snakeCaseName = path.parse(file).name;
|
||
|
const kebabCaseName = snakeCaseName.replace(/_/g, "-");
|
||
|
const ext = path.extname(file);
|
||
|
const newFileName = `${kebabCaseName}${ext}`;
|
||
|
|
||
|
fs.rename(
|
||
|
path.join(directoryPath, file),
|
||
|
path.join(directoryPath, newFileName),
|
||
|
(err) => {
|
||
|
if (err) {
|
||
|
console.error("Error renaming file:", err);
|
||
|
} else {
|
||
|
console.log(`Renamed: ${file} -> ${newFileName}`);
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
});
|
||
|
});
|
||
|
};
|
||
|
|
||
|
const directoryPath = "./src/svgs/fa";
|
||
|
convertSnakeToKebabCase(directoryPath);
|