欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

python實現復制大量文件功能

系統 1638 0

本文實例為大家分享了python實現復制大量文件的具體代碼,供大家參考,具體內容如下

本來是去項目公司拷數據,結果去了發現有500G,靠系統的復制功能怕是得好幾個小時,于是回來學一手操作,話不多說上代碼:

說明:CopyFiles1是可以將sourceDir連子目錄一起原樣復制到targetDir,而CopyFiles2是在sourceDir中篩選特定格式文件,然后將其直接放在targetDir中,會很亂,但是很快

            
import os
import time
import shutil
sourceDir = r"D:\copytest\datatest"
targetDir = r"D:\copytest\result"
copyFileCounts = 0
 
def CopyFiles1(sourceDir, targetDir):
#完全連子目錄也會復制好,美觀
  global copyFileCounts
  print(sourceDir )
  print("%s 當前處理文件夾%s已處理%s 個文件" %(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):
 
      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))):
 
        open(targetF, "wb").write(open(sourceF, "rb").read())
        print ("%s %s 復制完畢" %(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), targetF))
      else:
        print ("%s %s 已存在,不重復復制" %(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), targetF))
 
    if os.path.isdir(sourceF):
      copyFiles(sourceF, targetF)
 
def CopyFiles2(dir):
  #會將目錄下所有文件都復制在一起,速度快,可以篩選文件
  i=0
  for root,dir1,filename in os.walk(dir):
   #print(filename)
   for index in range(len(filename)):
    #print(os.path.splitext(filename[index])[1])
    #if os.path.splitext(filename[index])[1]=='.':#這里注意filename是個元組,splitext方法的時候只能是字符串
    if 1==1:
      #i+=1
      print('here')
      root1="D:\\copytest\\result3"
      old_path = os.path.join(root, filename[index])
      print(old_path)
      new_path = os.path.join(root1,filename[index])
      shutil.copyfile(old_path,new_path)
 
#print("總共有",i,"圖層文件被復制!")
 
if __name__ == "__main__":
 time_start = time.time()
 try:
  import psyco
  psyco.profile()
 except ImportError:
   pass
 #CopyFiles1(sourceDir,targetDir)
 CopyFiles2("D:/copytest/datatest")
 time_end = time.time()
 print('totally cost', time_end - time_start)
          

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产一级淫 | 黄毛片视频| 久久亚洲欧美日本精品品 | 精品国产第一国产综合精品gif | 欧美不卡 | 美日韩一区二区三区 | 久久久精| 成人免费一区二区三区视频网站 | 欧美一级黄视频 | 免费99视频 | 免费乱理伦片在线观看八戒 | 美女国产精品 | 欧美精品一区二区三区在线播放 | 波多野结衣亚洲一区 | 香蕉视频在线观看视频 | 色悠久久久久综合网伊人男男 | 男女黄 | 国产做a | 多女多p多杂交视频在线观看 | 国产色在线 | 欧美天天在线 | 午夜在线小视频 | 精品午夜寂寞黄网站在线 | 日韩精品一级毛片 | 国产精品久久久久久久久久红粉 | 成在线人免费视频一区二区三区 | 超碰人人在线 | 国产日产亚洲欧美综合另类 | 中文字幕亚洲第一 | 国内自拍偷拍 | 毛片免费观看视频 | 六月激情婷婷 | 国产精品97在线 | 日韩app | 国产激情久久久久久熟女老人AV | va在线| 久久我们这里只有精品国产4 | 日本男人天堂 | 欧美日韩精选 | feise.av| 91tv最新永久在线地址 |