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

Incorrect File Naming Pattern #518

Open
s3cy opened this issue Mar 8, 2025 · 0 comments
Open

Incorrect File Naming Pattern #518

s3cy opened this issue Mar 8, 2025 · 0 comments

Comments

@s3cy
Copy link

s3cy commented Mar 8, 2025

Hi, I noticed a potential issue with the file naming pattern in the code. Currently, the file is named using the following format:

file = f"{filename}_{counter:05}.json"

However, based on the logic in the ComfyUI project, specifically in this section:
https://github.com/comfyanonymous/ComfyUI/blob/be4e760648e0234f9202b9cbe7dcfb3bd307acb9/folder_paths.py#L352

    def map_filename(filename: str) -> tuple[int, str]:
        prefix_len = len(os.path.basename(filename_prefix))
        prefix = filename[:prefix_len + 1]
        try:
            digits = int(filename[prefix_len + 1:].split('_')[0])
        except:
            digits = 0
        return digits, prefix

Example 1: filename = "PoseKeypoint_00001_.json"

  1. Calculate prefix length: The length of filename_prefix is 12 ("PoseKeypoint").

  2. Extract prefix: prefix is filename[:13] (the first 13 characters), which is "PoseKeypoint_".

  3. Extract digits: The remaining part is "00001_.json", which is split to get "00001" and converted to the integer 1.

  4. Return result: (1, "PoseKeypoint_").

Example 2: filename = "PoseKeypoint_00001.json"

  1. Calculate prefix length: Same as above, the prefix length is 12.

  2. Extract prefix: prefix is still "PoseKeypoint_".

  3. Extract digits: The remaining part is "00001.json", which is split to get "00001.json". The conversion fails, so digits is set to 0.

  4. Return result: (0, "PoseKeypoint_").

Key Point: If filename_prefix does not include the trailing underscore, the second filename fails to convert the digits because the number is directly followed by .json, resulting in digits=0.

file = f"{filename}_{counter:05}_.json"

This change ensures that the file naming convention aligns with the validation logic in the code, which expects files to end with an underscore.

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

No branches or pull requests

1 participant