Python3文件重命名

2020-01-13 12:29:01 浏览数 (1)

代码语言:javascript复制
import sys, os, csv

data_file = 'C:/Users/81080/Desktop/class.csv'
im_file = 'D:/class_im/'
fileNames_1 = os.listdir('D:/class_im/')
csvfile = open(data_file, 'r')
csvreader = csv.reader(csvfile)
key_url_list = [line[:2] for line in csvreader]
for i in range(14499,len(key_url_list)):
    fileNames_1 = os.listdir('D:/class_im/')
    (key, id) = key_url_list[i]
    if key in fileNames_1:
        os.rename(os.path.join(im_file, key), os.path.join(im_file, id)   ".jpg")

0 人点赞