Fix: Separator-Bug, List-Support, Kategorie & Parent Directory
- Issue #10: Separator '_' wird nur noch bei nicht-leerem time_format eingefügt - Issue #6 & #8: Robuster List-Support für verschachtelte Listen - Issue #7: Kategorie von 'Custom Nodes' zu 'FilePath Utils' geändert - Feature: Parent Directory Output im FilePathExtractor hinzugefügt - Alle Tests bestanden (Einzelpfade, Listen, verschachtelte Listen)
This commit is contained in:
+43
-38
@@ -1,38 +1,43 @@
|
||||
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"
|
||||
|
||||
@staticmethod
|
||||
def IS_CHANGED():
|
||||
# Always return True to force the node to run on every iteration
|
||||
return True
|
||||
|
||||
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
|
||||
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 = "FilePath Utils"
|
||||
RETURN_TYPES = ("STRING", "STRING", "STRING")
|
||||
RETURN_NAMES = ("Filename", "Folder Path", "Combined Path")
|
||||
FUNCTION = "process"
|
||||
|
||||
@staticmethod
|
||||
def IS_CHANGED():
|
||||
# Always return True to force the node to run on every iteration
|
||||
return True
|
||||
|
||||
def process(self, file_prefix, time_format, output_folder, filetype):
|
||||
output_folder = output_folder or os.path.abspath("output")
|
||||
|
||||
# Erstelle den Basis-Namen mit oder ohne Zeitstempel
|
||||
if time_format and time_format.strip():
|
||||
current_time = datetime.now().strftime(time_format)
|
||||
filename = f"{file_prefix}_{current_time}"
|
||||
else:
|
||||
filename = file_prefix
|
||||
|
||||
# Füge Extension hinzu wenn vorhanden
|
||||
if filetype:
|
||||
filename = f"{filename}.{filetype}"
|
||||
|
||||
combined_path = os.path.join(output_folder, filename)
|
||||
return filename, output_folder, combined_path
|
||||
|
||||
+76
-71
@@ -1,71 +1,76 @@
|
||||
import os
|
||||
|
||||
|
||||
class FilePathExtractor:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"path": ("STRING", {"default": "", "multiline": True, "width": 400})
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "Custom Nodes"
|
||||
RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING", "STRING")
|
||||
RETURN_NAMES = ("File Name", "File Extension", "File Name With Extension", "Folder Name", "Folder Path")
|
||||
FUNCTION = "process"
|
||||
INPUT_IS_LIST = True
|
||||
OUTPUT_IS_LIST = (True, True, True, True, True)
|
||||
|
||||
@staticmethod
|
||||
def IS_CHANGED():
|
||||
# Always return True to force the node to run on every iteration
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _normalize_paths(cls, path):
|
||||
normalized_paths = []
|
||||
|
||||
def _flatten(value):
|
||||
if isinstance(value, (list, tuple)):
|
||||
for item in value:
|
||||
_flatten(item)
|
||||
return
|
||||
|
||||
if value is None:
|
||||
normalized_paths.append("")
|
||||
else:
|
||||
normalized_paths.append(str(value))
|
||||
|
||||
_flatten(path)
|
||||
|
||||
if not normalized_paths:
|
||||
return [""]
|
||||
|
||||
return normalized_paths
|
||||
|
||||
def process(self, path):
|
||||
paths = self._normalize_paths(path)
|
||||
|
||||
file_names = []
|
||||
file_extensions = []
|
||||
file_names_with_extension = []
|
||||
folder_names = []
|
||||
folder_paths = []
|
||||
|
||||
for path_item in paths:
|
||||
folder_part = os.path.dirname(path_item)
|
||||
# Keep original text when no directory part is present.
|
||||
folder_path = folder_part if folder_part else path_item
|
||||
folder_name = os.path.basename(folder_path)
|
||||
file_name_with_extension = os.path.basename(path_item)
|
||||
file_name, file_extension = os.path.splitext(file_name_with_extension)
|
||||
file_extension = file_extension[1:] if file_extension.startswith(".") else file_extension
|
||||
|
||||
file_names.append(file_name)
|
||||
file_extensions.append(file_extension)
|
||||
file_names_with_extension.append(file_name_with_extension)
|
||||
folder_names.append(folder_name)
|
||||
folder_paths.append(folder_path)
|
||||
|
||||
return file_names, file_extensions, file_names_with_extension, folder_names, folder_paths
|
||||
import os
|
||||
|
||||
|
||||
class FilePathExtractor:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"path": ("STRING", {"default": "", "multiline": True, "width": 400})
|
||||
}
|
||||
}
|
||||
|
||||
CATEGORY = "FilePath Utils"
|
||||
RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING", "STRING", "STRING")
|
||||
RETURN_NAMES = ("File Name", "File Extension", "File Name With Extension", "Folder Name", "Folder Path", "Parent Directory")
|
||||
FUNCTION = "process"
|
||||
INPUT_IS_LIST = True
|
||||
OUTPUT_IS_LIST = (True, True, True, True, True, True)
|
||||
|
||||
@staticmethod
|
||||
def IS_CHANGED():
|
||||
# Always return True to force the node to run on every iteration
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _normalize_paths(cls, path):
|
||||
normalized_paths = []
|
||||
|
||||
def _flatten(value):
|
||||
if isinstance(value, (list, tuple)):
|
||||
for item in value:
|
||||
_flatten(item)
|
||||
return
|
||||
|
||||
if value is None:
|
||||
normalized_paths.append("")
|
||||
else:
|
||||
normalized_paths.append(str(value))
|
||||
|
||||
_flatten(path)
|
||||
|
||||
if not normalized_paths:
|
||||
return [""]
|
||||
|
||||
return normalized_paths
|
||||
|
||||
def process(self, path):
|
||||
paths = self._normalize_paths(path)
|
||||
|
||||
file_names = []
|
||||
file_extensions = []
|
||||
file_names_with_extension = []
|
||||
folder_names = []
|
||||
folder_paths = []
|
||||
parent_directories = []
|
||||
|
||||
for path_item in paths:
|
||||
folder_part = os.path.dirname(path_item)
|
||||
# Keep original text when no directory part is present.
|
||||
folder_path = folder_part if folder_part else path_item
|
||||
folder_name = os.path.basename(folder_path)
|
||||
file_name_with_extension = os.path.basename(path_item)
|
||||
file_name, file_extension = os.path.splitext(file_name_with_extension)
|
||||
file_extension = file_extension[1:] if file_extension.startswith(".") else file_extension
|
||||
|
||||
# Parent Directory berechnen
|
||||
parent_dir = os.path.dirname(folder_path) if folder_path else ""
|
||||
|
||||
file_names.append(file_name)
|
||||
file_extensions.append(file_extension)
|
||||
file_names_with_extension.append(file_name_with_extension)
|
||||
folder_names.append(folder_name)
|
||||
folder_paths.append(folder_path)
|
||||
parent_directories.append(parent_dir)
|
||||
|
||||
return file_names, file_extensions, file_names_with_extension, folder_names, folder_paths, parent_directories
|
||||
|
||||
Reference in New Issue
Block a user