Update 更新文件名.py

This commit is contained in:
frxz751113
2024-09-15 13:25:52 +08:00
committed by GitHub
parent e3041f0c43
commit d3bea0a582
+9 -6
View File
@@ -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: