Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option for file name capitalization handling #450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alterxyz
Copy link

In this update, I have added a new option for file name capitalization handling, which allows users to convert specific parts of the file name to title case (first letter capitalized, other letters lowercase), while preserving the original case of the original_name. The previous code only supported two formats: all uppercase and all lowercase for whole file name.

To implement this feature, I added a new conditional branch to check whether the 'capitalization' setting in the configuration file is set to 'title'. Users can specify the delimiter (in this case, ']') and how to handle different parts of the file name in the configuration file according to their needs.

Possible future improvement: Support for extension capitalization.

I hope this change will provide more flexibility and customization options.

In this update, I have added a new option for file name capitalization handling, which allows users to convert specific parts of the file name to title case (first letter capitalized, other letters lowercase), while preserving the original case of the original_name. The previous code only supported two formats: all uppercase and all lowercase for whole file name.

To implement this feature, I added a new conditional branch to check whether the 'capitalization' setting in the configuration file is set to 'title'. Users can specify the delimiter (in this case, ']') and how to handle different parts of the file name in the configuration file according to their needs.

Possible future improvement: Support for extension capitalization.

I hope this change will provide more flexibility and customization options.
@CLAassistant
Copy link

CLAassistant commented Mar 22, 2023

CLA assistant check
All committers have signed the CLA.

@coveralls
Copy link

Coverage Status

Coverage: 90.553% (-0.06%) from 90.61% when pulling fdb6821 on alterxyz:patch-1 into 76ad823 on jmathai:master.

# name=%date [%city] %original_name.%extension
# Since strings before "]" are quite stable, it ensures that they can be split properly by "]" no matter what the original name is.
# "]" is replaceable.
return name.split(']', maxsplit=1)[0].title() + ']' + name.split(']', maxsplit=1)[1]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you proposing that text within []'s gets special treatment? Is the goal here that, for example, the i in img_0001.jpg does not get capitalized?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your reply.

Initially, I wanted to keep the original filename unchanged, but capitalize the first letter of the city name in the filename so it looks good. For example, a photo named iOS_IMG_0144.Heic would be renamed to:

└── 2023-Mar
│   ├── 25-235959 [Toronto] iOS-IMG_0144.heic

The iOS remains the same, while Heic is changed to heic to align with the requirements of other parts of this project.


After customizing my own naming rules, I thought it would be helpful to let people know that they can easily split and modify their filenames. I chose the "]" character as a good separator based on my naming rules.

For example, adding another elif statement and using the rsplit() function in the following code can help people to convert the filename extension to lowercase while keeping the rest of the filename in uppercase:

elif('File' in config and 'capitalization' in config['File'] and config['File']['capitalization'] == 'up_name_with_low_ext'):
            return name.rsplit('.', maxsplit=1)[0].upper() + '.' + name.rsplit('.', maxsplit=1)[1].lower()

Perhaps I should commit this code that is more suitable for others, rather than the one that is just for myself?

As a beginner in coding, please feel free to point out any issues with my code or ideas.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining, that makes sense.

As a beginner in coding, please feel free to point out any issues with my code or ideas.

This parsing logic is one of the more complex parts of this code base (as seen by the ratio of comments to code in get_file_name. Uppercasing the entire file name is easy to do here because we don't have to be precise - we just uppercase the whole thing.

If we want to capitalize specific parts of the file name it might more suitable to do it higher up in this function. Either in the for loop starting at line 151 or after the for loop when we interpolate into the templated string around line 210.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants