中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Python 文件夾復(fù)制

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用
#! /usr/bin/env python  
# -*- coding: utf-8 -*-  
#@author zcwang3@gmail.com  
#@version 2010-09-25 14:57  

import os  
import time  

sourceDir = r"\\\\192.168.3.250\\mmtimages" 
targetDir = r"D:\\mmtimages" 
copyFileCounts = 0 

def copyFiles(sourceDir, targetDir):  
    global copyFileCounts  
    print sourceDir  
    print u"%s 當(dāng)前處理文件夾%s已處理%s 個(gè)文件" %(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), sourceDir,copyFileCounts)  
    for f in os.listdir(sourceDir):  
        sourceF = os.path.join(sourceDir, f)  
        targetF = os.path.join(targetDir, f)  

        if os.path.isfile(sourceF):  
            #創(chuàng)建目錄  
            if not os.path.exists(targetDir):  
                os.makedirs(targetDir)  
            copyFileCounts += 1 

            #文件不存在,或者存在但是大小不同,覆蓋  
            if not os.path.exists(targetF) or (os.path.exists(targetF) and (os.path.getsize(targetF) != os.path.getsize(sourceF))):  
                #2進(jìn)制文件  
                open(targetF, "wb").write(open(sourceF, "rb").read())  
                print u"%s %s 復(fù)制完畢" %(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), targetF)  
            else:  
                print u"%s %s 已存在,不重復(fù)復(fù)制" %(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), targetF)  

        if os.path.isdir(sourceF):  
            copyFiles(sourceF, targetF)  

if __name__ == "__main__":  
    try:  
        import psyco  
        psyco.profile()  
    except ImportError:  
        pass 
    copyFiles(sourceDir,targetDir)

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:Python 簡單的代理服務(wù)器

下一篇:Apache Commons Codec 使用小結(jié)