#!/usr/bin/env python
# Version = 3.5.2

import shutil

base_dir = '/data/media/'
file = '/backup/tempimages/courseid.txt'
log = '/backup/tempimages/copy.log'
with open(file) as f:
    for item in f:
        try:
            srcDir = base_dir+item.strip()[:12]+'/'+item.strip()[12:]+'/images/'
            dstDir = "/backup/tempimages/media/"+item.strip()[:12]+'/'+item.strip()[12:]+'/images/'
            shutil.copytree(srcDir, dstDir)
            with open(log,'a') as l:
                l.write('---DONE---'+item.strip()[:12]+'/'+item.strip()[12:]+'\n')
        except Exception as err:
            print(err)



[root@web-25 tempimages]# more courseid.txt
20080000620204
20170092133801
20100000763203
20090000670301
20070000273305
20070000273304
20070000273301
20070000273303
20070000273302