逐行读取文件,根据路径进行拷贝新目录,记录不存在文件
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import os
import importlib,sys
import shutil
importlib.reload(sys)
# sys.setdefaultencoding('utf8')
print (sys.getdefaultencoding())
def main():
logData = open("./log.txt", 'w+')
f = open("./copypng.txt",'r+', encoding='UTF-8', errors='ignore')
all_the_lines=f.readlines()
f.close()
for line in all_the_lines:
line = line.replace('res/', '')
oldPath = os.getcwd() + '/old_opui_png/' + line.strip()
dirPath = os.getcwd() + '/new_opui_png/' + line.strip()
if os.access(oldPath, os.F_OK) :
targetPath = dirPath.split(os.path.basename(dirPath))[0]
if not os.path.isdir(targetPath):
os.makedirs(targetPath)
shutil.copy(oldPath, dirPath)
else :
print('not find ------>' + line.strip(), file=logData)
if __name__=='__main__':
main()