代码拉取完成,页面将自动刷新
import os
# Define the directory path where your files are located
directory = 'uploads/samsung/'
# Function to rename files
# Function to rename files
def rename_files(directory):
for filename in os.listdir(directory):
# 检查文件名是否包含两个或更多的下划线
if filename.count('_') >= 2:
parts = filename.split('_')
# 获取第二个下划线后的部分并进行替换
if parts[2] == '0':
parts[2] = '1'
elif parts[2] == '1':
parts[2] = '2'
elif parts[2] == '3':
parts[2] = '2'
elif parts[2] == '4':
parts[2] = '3'
new_filename = '_'.join(parts)
old_filepath = os.path.join(directory, filename)
new_filepath = os.path.join(directory, new_filename)
os.rename(old_filepath, new_filepath)
print(f'Renamed: {old_filepath} -> {new_filepath}')
else:
print(f'Skipped: {filename}')
rename_files(directory)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。