使用python脚本对文件处理

使用python脚本对文件处理
import shutil
import os
os.mkdir('file_400')
fr = open("list.txt")
lines = fr.readlines()
i = 0
fr_word = open('word.txt')
lines_word =fr_word.readlines()
for line in lines:
    line = line.strip('\n')
#move needed file to new file
    shutil.copy('train_jpg/' + line,'file_400')
#rename the needed file to   
    os.rename('file_400/' + line,'file_400/' + lines_word[i].strip('\n') +'_'+ line )
    i = i + 1


posted @ 2018-04-17 10:15  开往春天的拖拉机  阅读(308)  评论(0编辑  收藏  举报