互联网企业公司,班级优化大师官方网站,网站开发接私活的经理,免备案域名是什么背景需求下载教程#xff0c;手动输入编号#xff0c;有一个编号错误#xff0c;导致后面所有编号都错了。30实际是29#xff0c;以此类推怎样才能快速修改编号数字#xff1f;前期考虑到可能要改编号#xff0c;所以在每个编号后面加“ ”#xff08;空格#xff09;手动输入编号有一个编号错误导致后面所有编号都错了。30实际是29以此类推怎样才能快速修改编号数字前期考虑到可能要改编号所以在每个编号后面加“ ”空格并保证文件名其他位置没有空格用代码先在编号文件名前面 再加一个“29 ”的编号判断添加顺序是否正确万一有搞错项目的情况发生。import os
import timepath rD:\test\iVX\12 官网教程\04 营销互动改编号# UI搭建
a29
fileListos.listdir(path)for file in fileList:# split_str file.split( )# newname1 split_str[0] # _的第0部分序号
# newname2 split_str[1] # _的第0部分序号 # newnamenewname1mp4newname{} .format(a)fileoldname_path os.path.join(path,file)# 文件新路径newname_path os.path.join(path,newname)# 新旧对调os.rename(oldname_path, newname_path)a1结果可以看到左边的新编号与右边的错误号码差一位说明新序号正确再把文件名里面的第二个号码删除import os
import timepath rD:\test\iVX\12 官网教程\04 营销互动改编号# UI搭建fileListos.listdir(path)for file in fileList:split_str file.split( )newname1 split_str[0] # _的第0部分序号 newname2 split_str[2] # _的第0部分序号# newnamenewname1mp4newnamenewname1 newname2oldname_path os.path.join(path,file)# 文件新路径newname_path os.path.join(path,newname)# 新旧对调os.rename(oldname_path, newname_path)
用同样的方法修改其他编号。顺利获得正确号码运行两个代码有点麻烦。可以把两个代码组合在一起。import os
import timepath rD:\test\iVX\12 官网教程\\09 连接a81
fileListos.listdir(path)for file in fileList:split_str file.split( ) #空格作为分割点提取1 newname1 split_str[1] # _的第1部分序号 newname{} .format(a)newname1# 删除了错误的序号前面加上正确的序号空格oldname_path os.path.join(path,file)# 文件新路径newname_path os.path.join(path,newname)# 新旧对调os.rename(oldname_path, newname_path) a1问题发现中间有两个空格path rD:\test\iVX\12 官网教程\kongfileListos.listdir(path)for file in fileList:split_str file.split( )newname1 split_str[0] # _的第0部分序号 print(newname1)newname2 split_str[2] # _的第0部分序号 print(newname2)newnamenewname1 newname2oldname_path os.path.join(path,file)# 文件新路径newname_path os.path.join(path,newname)# 新旧对调os.rename(oldname_path, newname_path)空格一样大小1个空格重要提示不能保证程序正确时最好把数据备份否则如果改名失败文件名上的所有的信息都会被删除无法恢复切记要复制一份 切记要复制一份 切记要复制一份 重要的事情说三次