最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python如何實(shí)現(xiàn)復(fù)制目錄到指定目錄

 更新時(shí)間:2020年02月13日 10:38:13   作者:super_xxt  
這篇文章主要為大家介紹了python如何實(shí)現(xiàn)復(fù)制目錄到指定目錄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python復(fù)制目錄到指定目錄的具體代碼,供大家參考,具體內(nèi)容如下

保存下面代碼為一個(gè)文件直接運(yùn)行

import os
import time
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__":
 copyFiles('/content/chest_xray/', '/content/drive/My Drive/chest_xray/')

刪除非空目錄的所有有文件,包含目錄本身

import shutil
shutil.rmtree('D:/content/')

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

大兴区| 永城市| 海晏县| 马龙县| 金溪县| 开远市| 托克托县| 阳春市| 吉木萨尔县| 定南县| 衡南县| 托克逊县| 文成县| 江门市| 镶黄旗| 永济市| 淮安市| 牡丹江市| 郑州市| 陕西省| 陈巴尔虎旗| 四川省| 扎囊县| 万州区| 灌阳县| 常宁市| 黎川县| 湖州市| 卢龙县| 和林格尔县| 友谊县| 曲周县| 望谟县| 肥城市| 哈尔滨市| 巴林右旗| 文山县| 邵武市| 沧源| 潮安县| 灵石县|