From 5fddb7aed2826e5855720211aac7c0cd0d18b7b3 Mon Sep 17 00:00:00 2001 From: MeeeyoAI Date: Mon, 21 Apr 2025 17:06:40 +0800 Subject: [PATCH] Update --- __init__.py | 4 ++- meyo_node_File.py | 67 +++++++++++++++++++++++++++++++++++++++++ meyo_node_Functional.py | 2 +- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 7c134ae..40b2ba0 100644 --- a/__init__.py +++ b/__init__.py @@ -49,7 +49,8 @@ NODE_CLASS_MAPPINGS = { "CustomCrop": CustomCrop, "SaveImagEX": SaveImagEX, - "FileCopyCutNode": FileCopyCutNode, + "FileCopyCutNode": FileCopyCutNode, + "FileDeleteNode": FileDeleteNode, "FileListAndSuffix": FileListAndSuffix, "ReadExcelData": ReadExcelData, "WriteExcelData": WriteExcelData, @@ -108,6 +109,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { "SaveImagEX": "保存图像(meeeyo.com)", "FileCopyCutNode": "文件操作(meeeyo.com)", + "FileDeleteNode": "清理文件(meeeyo.com)", "FileListAndSuffix": "从路径加载(meeeyo.com)", "ReadExcelData": "读取表格数据(meeeyo.com)", "WriteExcelData": "写入表格数据(meeeyo.com)", diff --git a/meyo_node_File.py b/meyo_node_File.py index 0292c60..5a3eb65 100644 --- a/meyo_node_File.py +++ b/meyo_node_File.py @@ -427,6 +427,73 @@ class FileCopyCutNode: return (result,) +#======清理文件 +class FileDeleteNode: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "target_paths": ("STRING", {"default": "", "multiline": True}), + }, + "optional": { + "any": ("*",), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("result",) + FUNCTION = "delete_files" + CATEGORY = "Meeeyo/File" + DESCRIPTION = "如需更多帮助或商务需求(For tech and business support)+VX/WeChat: meeeyo" + + def delete_files(self, target_paths, **kwargs): + result = "执行失败" + deleted_count = 0 + total_count = 0 + error_messages = [] + + try: + # 拆分多行路径并去空 + paths = [path.strip() for path in target_paths.split('\n') if path.strip()] + total_count = len(paths) + + if total_count == 0: + raise Exception("未提供有效的文件路径") + + # 遍历所有路径进行删除 + for path in paths: + if not os.path.exists(path): + error_messages.append(f"路径不存在: {path}") + continue + + try: + # 删除文件或文件夹 + if os.path.isfile(path): + os.remove(path) + else: + shutil.rmtree(path) + deleted_count += 1 + except Exception as e: + error_messages.append(f"删除失败: {path} - {str(e)}") + + # 构建结果字符串 + result_parts = [] + if deleted_count > 0: + result_parts.append(f"成功删除 {deleted_count}/{total_count} 个路径") + + if error_messages: + result_parts.append("\n错误详情:") + result_parts.extend(error_messages) + + result = "\n".join(result_parts) + + except Exception as e: + result = f"执行失败: {str(e)}" + + return (result,) + + + #======文件路径和后缀统计 class FileListAndSuffix: def __init__(self): diff --git a/meyo_node_Functional.py b/meyo_node_Functional.py index d053414..bf20f93 100644 --- a/meyo_node_Functional.py +++ b/meyo_node_Functional.py @@ -83,7 +83,7 @@ class ReadWebNode: RETURN_TYPES = ("STRING",) FUNCTION = "fetch_data" - CATEGORY = "Meyo/Functional" + CATEGORY = "Meeeyo/Functional" DESCRIPTION = "如需更多帮助或商务需求(For tech and business support)+VX/WeChat: meeeyo" def IS_CHANGED():