From d3bea0a582d5366723e52d7942cb3781cf6c848c Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:25:52 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/更新文件名.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/py/更新文件名.py b/py/更新文件名.py index 7d98967..6d54ecd 100644 --- a/py/更新文件名.py +++ b/py/更新文件名.py @@ -11,13 +11,16 @@ all_files = os.listdir(os.getcwd()) # 要重命名的文件名列表(初始文件名) initial_filenames = ['综合源.m3u', '组播优选.txt', '综合源.txt'] -# 删除初始文件名前面带有任意字符的文件 +# 删除初始文件名前面带有非空任意字符的文件 for old_filename in all_files: - if any(not old_filename.startswith(current_date) and old_filename.endswith(init_filename) for init_filename in initial_filenames): - full_old_path = os.path.join(os.getcwd(), old_filename) - if os.path.exists(full_old_path): - os.remove(full_old_path) - print(f"Deleted {old_filename}") + for init_filename in initial_filenames: + if old_filename.endswith(init_filename) and not old_filename.startswith(current_date): + non_empty_prefix = old_filename[:-len(init_filename)] + if non_empty_prefix: + full_old_path = os.path.join(os.getcwd(), old_filename) + if os.path.exists(full_old_path): + os.remove(full_old_path) + print(f"Deleted {old_filename}") # 重命名初始文件名的文件 for old_filename in all_files: