From 5e9ed3eaaa9ef85557eadf0abb447ec8b817237d Mon Sep 17 00:00:00 2001 From: HECer Date: Sun, 7 Jul 2024 16:51:08 +0200 Subject: [PATCH] - Updated Description and Code --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++- __init__.py | 11 +++++++++++ file_path_creator.py | 33 +++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 __init__.py create mode 100644 file_path_creator.py diff --git a/README.md b/README.md index eab0927..ef6f5cd 100644 --- a/README.md +++ b/README.md @@ -1 +1,46 @@ -# ComfyUI-FilePathCreator \ No newline at end of file +# ComfyUI-FilePathCreator + +## 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. + +## Features +- **Customizable Filename Prefix**: Define a custom prefix for your filenames to easily identify and categorize your files. +- **Dynamic Timestamps**: Generate filenames with current timestamps using customizable time formats. +- **Optional Output Folder**: Specify an output folder where files should be saved. If not specified, a default local output folder is used. +- **File Type Specification**: Choose the file extension for the generated filenames. If the file type is left empty, the filename is generated without an extension. + +## Inputs +1. **file_prefix** (required): + - Type: STRING + - Default: `"output"` + - Description: The prefix to be used for the generated filename. + +2. **time_format** (required): + - Type: STRING + - Default: `"%Y-%m-%d-%H%M%S"` + - Description: The format for the timestamp in the filename. Uses Python's `datetime` format codes. + +3. **output_folder** (optional): + - Type: STRING + - Default: `""` + - Description: The folder path where the file should be saved. Defaults to a local "output" folder if left empty. + +4. **filetype** (optional): + - Type: STRING + - Default: `"txt"` + - Description: The file extension for the generated filename. If left empty, no file extension is added. + +## Outputs +1. **Filename**: The generated filename based on the prefix and timestamp. +2. **Folder Path**: The path of the output folder. +3. **Combined Path**: The full path combining the output folder and filename. + +## Example Usage +After installing the `ComfyUI-FilePathCreator`, you can use it to generate filenames like `output_2023-07-07-143022.txt` and save them in a specified folder. This is particularly useful for batch processing or saving results from automated workflows in a consistent and organized manner. + + +Licensing +This project is licensed under the MIT License. See the LICENSE file for more details. + +Contributions +Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository. \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..7613255 --- /dev/null +++ b/__init__.py @@ -0,0 +1,11 @@ +from .file_path_creator import FilePathCreator + +NODE_CLASS_MAPPINGS = { + "FilePathCreator": FilePathCreator +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "FilePathCreator": "File Path Creator" +} + +__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] diff --git a/file_path_creator.py b/file_path_creator.py new file mode 100644 index 0000000..2a038d5 --- /dev/null +++ b/file_path_creator.py @@ -0,0 +1,33 @@ +import os +from datetime import datetime + +class FilePathCreator: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "file_prefix": ("STRING", {"default": "output"}), + "time_format": ("STRING", {"default": "%Y-%m-%d-%H%M%S"}) + }, + "optional": { + "output_folder": ("STRING", {"default": ""}), + "filetype": ("STRING", {"default": "txt"}) + } + } + + CATEGORY = "Custom Nodes" + RETURN_TYPES = ("STRING", "STRING", "STRING") + RETURN_NAMES = ("Filename", "Folder Path", "Combined Path") + FUNCTION = "process" + + def process(self, file_prefix, time_format, output_folder, filetype): + output_folder = output_folder or os.path.abspath("output") + current_time = datetime.now().strftime(time_format) + + if filetype: + filename = f"{file_prefix}_{current_time}.{filetype}" + else: + filename = f"{file_prefix}_{current_time}" + + combined_path = os.path.join(output_folder, filename) + return filename, output_folder, combined_path