Last active
June 4, 2020 04:11
-
-
Save fourirakbar/e902c94bb7f7ce1d761091a76d9b8c85 to your computer and use it in GitHub Desktop.
Change filename from snake case to camel case using python
This file contains hidden or 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
| #!/usr/local/bin/python | |
| import os | |
| import sys | |
| path = sys.argv[1] | |
| def snake_to_camel(path): | |
| for root, dirs, files in os.walk(path): | |
| for file in files: | |
| if "-" in file: | |
| name = ''.join(word.title() | |
| for word in file.split('-')) | |
| res = name[0].lower() + name[1:] | |
| sep = "." | |
| result = res.split(sep, 1)[0] | |
| splitString = res.split(".") | |
| lowerCase = splitString[1][0].lower() | |
| result1 = splitString[1][1:] | |
| result2 = splitString[0]+"."+lowerCase+result1 | |
| print("Change "+root+"/"+file+" to "+root+"/"+result2) | |
| os.rename(root+"/"+file, root+"/"+result2) | |
| if __name__ == '__main__': | |
| snake_to_camel(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment