diff --git a/README.md b/README.md index 6539696d..3b7cd8e4 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,4 @@ Sr no | Project Name | Author 36 | [Compress file and folders](https://github.com/chavarera/python-mini-projects/tree/master/projects/write%20script%20to%20compress%20folder%20and%20files) | [Gaodong](https://github.com/xlgd) 37 | [Find IMDB movie ratings](https://github.com/chavarera/python-mini-projects/tree/master/projects/Find%20IMDb%20rating) | [ShivSt](https://github.com/ShivSt) 38 | [Convert dictionary to python object](https://github.com/chavarera/python-mini-projects/tree/master/projects/convert_dictionary_to_python_object) | [Varun-22](https://github.com/Varun-22) +39 | [move files to alphabetically arranged folders](https://github.com/chavarera/python-mini-projects/tree/master/projects/Write%20script%20to%20move%20files%20into%20alphabetically%20ordered%20folder) | [Chathura Nimesh](https://github.com/kana800/) diff --git a/standardize_project_name.py b/standardize_project_name.py new file mode 100644 index 00000000..edd4d37c --- /dev/null +++ b/standardize_project_name.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +import os + +# Using os module to convert the file/folder's name +projects_old = os.listdir("projects") +projects_new = [] +for project in projects_old: + name_old = project.lower() + name = "" + n = 0 + for c in name_old: + if ord(c) in range(97, 123) or c == ".": + name += c + n = 1 + elif n == 1: + name += " " + n += 1 + else: + pass + + name_new = "" + for word in name.split(): + if word in [ + "write", + "create", + "script", + "a", + ]: # the list can be configured as per future requirement + pass + else: + name_new = " ".join([f"{name_new}", f"{word}"]).strip() + + if name_new.split()[0] in [ + "to", + " ", + ]: # this list will provide extra truncation at statring word of name + name_new = " ".join(name_new.split()[1:]).strip() + + projects_new.append(name_new) + +for i in range(len(projects_new)): + os.rename(f"projects/{projects_old[i]}", f"projects/{projects_new[i]}")