From 4e69a15886d1d2dcdaf6ff71443357cf9c8d62ed Mon Sep 17 00:00:00 2001 From: skycoder182 <212504411+skycoder182@users.noreply.github.com> Date: Tue, 20 May 2025 10:28:30 +0200 Subject: [PATCH] first commit --- LICENSE | 21 ++++++++++++++++++++ README.md | 41 ++++++++++++++++++++++++++++++++++++++++ __init__.py | 0 extract_trim_filename.py | 34 +++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 __init__.py create mode 100644 extract_trim_filename.py diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fad431c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Skycoder182 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..53f5445 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# ComfyUI Filename Tools + +Custom nodes for ComfyUI to extract and optionally trim filenames from file paths. + +## Features + +- Extract filename from a full file path +- Optionally remove everything from a specified marker +- Automatically removes the file extension + +## Node: Extract & Trim Filename (No Extension) + +### Inputs + +- `file_path` (STRING): Full path to the file (e.g., `C:/images/image_upscaled_001.png`) +- `trim_marker` (STRING): Optional marker to trim from (e.g., `_upscaled`) + +### Output + +- Filename without extension, trimmed at the marker (if found) + +### Example + +**Input path:** +`C:/Test/image_upscaled_001.jpg` +**Marker:** `_upscaled` +**Output:** `image` + +## Installation + +1. Clone or download this repository into your `ComfyUI/custom_nodes/` folder: + +``` +git clone https://github.com/yourusername/comfyui-filename-tools.git +``` + +2. Restart ComfyUI + +## License + +This project is licensed under the MIT License. diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/extract_trim_filename.py b/extract_trim_filename.py new file mode 100644 index 0000000..ade1997 --- /dev/null +++ b/extract_trim_filename.py @@ -0,0 +1,34 @@ + +import os + +class ExtractAndTrimFilename: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "file_path": ("STRING", {"default": "C:/Images/Image_xyz_123.png"}), + "trim_marker": ("STRING", {"default": "", "multiline": False}), + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("processed_filename",) + FUNCTION = "extract_and_trim" + CATEGORY = "Utils" + + def extract_and_trim(self, file_path, trim_marker): + filename = os.path.basename(file_path) + name, _ = os.path.splitext(filename) + if trim_marker: + index = name.find(trim_marker) + if index != -1: + name = name[:index] + return (name,) + +NODE_CLASS_MAPPINGS = { + "ExtractAndTrimFilename": ExtractAndTrimFilename +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "ExtractAndTrimFilename": "Extract & Trim Filename (No Extension)" +}