- some improvements of the FilePathExtractor node (is also now capeable of handling non existent paths and files)

- added screenshot for the FilePathExtractor-Node
- edited the readme file
This commit is contained in:
HECer
2024-10-20 16:40:00 +02:00
parent a22bd14043
commit a374897357
4 changed files with 25 additions and 27 deletions
+9 -7
View File
@@ -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.
+16 -20
View File
@@ -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

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB