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: