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

python2.7實(shí)現(xiàn)復(fù)制大量文件及文件夾資料

系統(tǒng) 2073 0

需求: 拷大量數(shù)據(jù),發(fā)現(xiàn)有2000G,靠系統(tǒng)的復(fù)制功能怕是得好幾個(gè)小時(shí),于是回來學(xué)一手操作,話不多說上代碼:

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

            
import os
import time
import shutil
sourceDir = r"D:\copytest\datatest"
targetDir = r"D:\copytest\result"
copyFileCounts = 0
 
def CopyFiles1(sourceDir, targetDir):
#完全連子目錄也會(huì)復(fù)制好,美觀
  global copyFileCounts
  print(sourceDir )
  print("%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):
 
      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 復(fù)制完畢" %(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), targetF))
      else:
        print ("%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)
 
def CopyFiles2(dir):
  #會(huì)將目錄下所有文件都復(fù)制在一起,速度快,可以篩選文件
  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是個(gè)元組,splitext方法的時(shí)候只能是字符串
    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,"圖層文件被復(fù)制!")
 
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)
 
#實(shí)戰(zhàn)代碼
#!/usr/bin/python2
# coding=UTF-8
#@author neo_will
#version 2019-04-02 10:39
 
import os
import os.path
import shutil
import time, datetime
 
#fpath_2018 = [1207, 1121, 1120, 1119, 1112, 1101, 1025, 1009, 0704, 0608, 0531, 0530, 0517, 0502, 0418, 0330, 0201, 0131]
#sourceDir=r"F:\LEVEL2_shanghai\2018\fpath_2018[0:]"
#des_dir=r"G:\MarketDataSupplement\shanghai\2018\fpath_2018[0:]"
#原始目錄和拷貝到的目錄地址
sourceDir = r"D:\tools\wj"
targetDir = r"D:\Users\wj"
copyFileCounts = 0
 
#定義拷貝文件的函數(shù)
def copyFiles(sourceDir, targetDir):
 global copyFileCounts
 print (sourceDir )
 print ("%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
 
  #文件不存在的話,或者存在但是大小存在差異不同,執(zhí)行完全覆蓋操作
  if not os.path.exists(targetF) or (os.path.exists(targetF) and (os.path.getsize(targetF) != os.path.getsize(sourceF))):
  #二進(jìn)制文件
  open(targetF, "wb").write(open(sourceF, "rb").read())
  print u"%s %s copy over" %(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), targetF)
  else:
   print("%s %s is exists,please don't copy more" %(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())), targetF))
 
 if os.path.isdir(sourceF):
  copyFiles(sourceF, targetF)
 
if __name__ == "__main__":
 time_start = time.time()
 try:
 import psyco
 psyco.profile()
 except ImportError:
 pass
 #copyFiles(sourceDir,targetDir)
 copyFiles(r"D:\tools\wj",r"D:\Users\wj")
 time_end = time.time()
 print('totally cost', time_end - time_start) 
          

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


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 青青青国产观看免费视频 | 欧美激情免费观看一区 | 国产精品久久久久无码人妻 | 精品无人乱码一区二区三区 | 精品一区二区三区免费看 | 一级视频在线播放 | 国产日韩第一页 | 日本大片在线观看免费视频 | 亚洲欧美日韩精品一区 | 成人福利视频在线看高清观看 | 精品久久中文字幕 | 国产成人综合一区二区三区 | 黄网页在线观看 | 99热最新网址 | 56av国产精品久久久久久久 | 日韩成人黄色 | 日韩一区二区在线视频 | 成人天堂资源www在线 | 久久综合九九 | 午夜在线 | 欧美三级视频 | 激情综合五月亚洲婷婷 | 午夜欧美一区二区三区在线播放 | www.久久精品 | 欧美日韩综合视频 | 特黄特色大片免费视频大全 | 波多野结衣中文在线观看 | 天天色天天射天天干 | 欧美高清另类自拍视频在线看 | 日本黄色激情视频 | 成人一级黄色大片 | 中文字幕av亚洲精品一部二部 | 国产精品你懂的在线播放 | 久久99精品久久久久久琪琪 | 久久www免费人成看片色多多 | xx00视频| 91成人国产网站在线观看 | 黄网站视频在线观看 | 亚洲精品久久久久综合中文字幕 | 九色av | 一本伊大人香蕉久久网手机 |