Update 更新文件名.py
This commit is contained in:
+9
-6
@@ -11,13 +11,16 @@ all_files = os.listdir(os.getcwd())
|
|||||||
# 要重命名的文件名列表(初始文件名)
|
# 要重命名的文件名列表(初始文件名)
|
||||||
initial_filenames = ['综合源.m3u', '组播优选.txt', '综合源.txt']
|
initial_filenames = ['综合源.m3u', '组播优选.txt', '综合源.txt']
|
||||||
|
|
||||||
# 删除初始文件名前面带有任意字符的文件
|
# 删除初始文件名前面带有非空任意字符的文件
|
||||||
for old_filename in all_files:
|
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):
|
for init_filename in initial_filenames:
|
||||||
full_old_path = os.path.join(os.getcwd(), old_filename)
|
if old_filename.endswith(init_filename) and not old_filename.startswith(current_date):
|
||||||
if os.path.exists(full_old_path):
|
non_empty_prefix = old_filename[:-len(init_filename)]
|
||||||
os.remove(full_old_path)
|
if non_empty_prefix:
|
||||||
print(f"Deleted {old_filename}")
|
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:
|
for old_filename in all_files:
|
||||||
|
|||||||
Reference in New Issue
Block a user