WASasquatch / was-node-suite-comfyui

An extensive node suite for ComfyUI with over 210 new nodes
MIT License
1.19k stars 178 forks source link

Adjust load_images Method to Ensure Correct File Paths #100

Closed lcolok closed 1 year ago

lcolok commented 1 year ago

This pull request addresses an issue found in the load_images method of the BatchImageLoader class, where the method could potentially generate incorrect and duplicated file paths.

The load_images function used the glob.glob function to get the filenames from a specific directory, and then it appended the directory path to the filenames. However, since glob.glob already returns the full path (including the directory path), appending the directory path again resulted in duplicated paths.

To fix this issue, the code was refactored to add the result from glob.glob directly to self.image_paths, as glob.glob already provides a complete path. Furthermore, to handle all potential edge cases, the absolute path of each file is ensured using os.path.abspath.

The revised load_images method is as follows:

def load_images(self, directory_path, pattern):
    for file_name in glob.glob(os.path.join(directory_path, pattern), recursive=True):
        if file_name.lower().endswith(ALLOWED_EXT):
            # Ensure the file path is absolute
            abs_file_path = os.path.abspath(file_name)
            self.image_paths.append(abs_file_path)

With this change, we can now ensure that the load_images method always generates correct file paths, regardless of whether glob.glob returns relative or absolute paths.

Please let me know if you have any questions or concerns about this change.

WASasquatch commented 1 year ago

Looks good. Thanks for the PR.