diff --git a/README.md b/README.md index e2cec8d..4b09b91 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ComfyUI-FilePathCreator -![Diagram](images/example.png) +![Diagram](images/FilePathCreator.png) ## Overview The `ComfyUI-FilePathCreator` is a custom node extension for ComfyUI designed to generate dynamic filenames based on user-defined parameters. This node helps streamline the process of creating organized and timestamped filenames, ideal for saving output files in a structured manner. @@ -42,6 +42,8 @@ After installing the `ComfyUI-FilePathCreator`, you can use it to generate filen ## FilePathExtractor +![Diagram](images/FilePathExtractor.png) + ### Overview The `FilePathExtractor` is a custom node extension for ComfyUI designed to extract components from a given file or folder path. This node facilitates the decomposition of file paths into understandable and reusable parts, enhancing workflow automation and path management. @@ -67,12 +69,12 @@ The `FilePathExtractor` is a custom node extension for ComfyUI designed to extra 5. **Folder Path**: The absolute path to the folder. ### Example Usage -After installing the `FilePathExtractor`, you can input a file path like `C:/Users/Username/Documents/report.pdf` and obtain: -- **File Name**: `report` -- **File Extension**: `pdf` -- **File Name With Extension**: `report.pdf` -- **Folder Name**: `Documents` -- **Folder Path**: `C:/Users/Username/Documents` +After installing the `FilePathExtractor`, you can input a file path like `C:/Folder/FolderName/Filename.png` and obtain: +- **File Name**: `Filename` +- **File Extension**: `png` +- **File Name With Extension**: `Filename.png` +- **Folder Name**: `FolderName` +- **Folder Path**: `C:/Folder/FolderName` ## Licensing This project is licensed under the MIT License. See the LICENSE file for more details. diff --git a/file_path_extractor.py b/file_path_extractor.py index 6b69627..6b77320 100644 --- a/file_path_extractor.py +++ b/file_path_extractor.py @@ -5,7 +5,7 @@ class FilePathExtractor: def INPUT_TYPES(cls): return { "required": { - "path": ("STRING", {"default": ""}) + "path": ("STRING", {"default": "", "multiline": True, "width": 400}) # Adjust height } } @@ -16,26 +16,22 @@ class FilePathExtractor: @staticmethod def IS_CHANGED(): + # Always return True to force the node to run on every iteration return True def process(self, path): - if os.path.isfile(path): - file_name_with_extension = os.path.basename(path) - file_name = os.path.splitext(file_name_with_extension)[0] - file_extension = os.path.splitext(path)[1][1:] - folder_path = os.path.dirname(path) - folder_name = os.path.basename(folder_path) - elif os.path.isdir(path): - file_name = "" - file_extension = "" - folder_path = os.path.abspath(path) - folder_name = os.path.basename(folder_path) - file_name_with_extension = "" - else: - file_name = "" - file_extension = "" - folder_path = "" - folder_name = "" - file_name_with_extension = "" + # Check if the path exists at all + # Default values for non-existing paths + file_name = "" + file_extension = "" + file_name_with_extension = "" + folder_name = "" + folder_path = "" + + folder_path = os.path.dirname(path) if os.path.dirname(path) else path # Use folder part of the path, even if it doesn't exist + folder_name = os.path.basename(folder_path) + file_name_with_extension = os.path.basename(path) + file_name, file_extension = os.path.splitext(file_name_with_extension) + file_extension = file_extension[1:] # Strip leading dot from extension - return file_name, file_extension, file_name_with_extension, folder_name, folder_path + return file_name, file_extension, file_name_with_extension, folder_name, folder_path \ No newline at end of file diff --git a/images/example.png b/images/FilePathCreator.png similarity index 100% rename from images/example.png rename to images/FilePathCreator.png diff --git a/images/FilePathExtractor.png b/images/FilePathExtractor.png new file mode 100644 index 0000000..76d40fd Binary files /dev/null and b/images/FilePathExtractor.png differ