修改添加网址的教程文件名

import os
import os.path
rootname = 'D:\Python\spider3.6'
rootdir = os.listdir(rootname)
for z in rootdir[1:]:
file_detail= rootname+'\\'+z
dir_detail = os.listdir(file_detail)
for i in dir_detail:
file_name = file_detail + '\\' + i
print(file_detail+'\\'+i)
# print(i[21:])
os.rename(file_detail + '\\' + i,file_detail+'\\'+i[21:])

import os
import os.path
rootname = 'D:\Python\spider3.6'
rootdir = os.listdir(rootname)
for z in rootdir[1:]:
file_detail= rootname+'\\'+z
dir_detail = os.listdir(file_detail)
for i in dir_detail:
h = '\\'
print(file_detail+h+i)
h = str(h)
print(i)
k = i.replace('讲',':')
os.rename(file_detail+'{}'.format(h)+i,file_detail+'{}'.format(h)+k)


posted @ 2018-01-21 04:16  hyolyn  阅读(140)  评论(0编辑  收藏  举报