Created
June 9, 2019 10:15
-
-
Save aminnairi/af52d416cd9105b96402fab0e7cc28de to your computer and use it in GitHub Desktop.
Capitalize files in a directory recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { readdirSync, statSync, renameSync } = require('fs'); | |
function capitalize(input) { | |
return input.slice(0, 1).toUpperCase() + input.slice(1); | |
} | |
function recursivelyCapitalizeFilesAndDirectories(path) { | |
for (const file of readdirSync(path)) { | |
const capitalizedFile = capitalize(file); | |
renameSync(`${path}/${file}`, `${path}/${capitalizedFile}`); | |
if (statSync(`${path}/${capitalizedFile}`).isDirectory()) { | |
recursivelyCapitalizeFilesAndDirectories(`${path}/${capitalizedFile}`); | |
} | |
} | |
} | |
recursivelyCapitalizeFilesAndDirectories('www/resources/components') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment