python拷贝目录下的文件


#!/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

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM