1 Star 0 Fork 0

Nuyoah/scaning_block

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
rename.py 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
Nuyoah 提交于 2024-07-05 19:22 . feat:增加批量检测识别结果参数
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)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiaoshengdi/scaning_block.git
git@gitee.com:xiaoshengdi/scaning_block.git
xiaoshengdi
scaning_block
scaning_block
master

搜索帮助