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

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

 更新時(shí)間:2019年08月31日 16:32:00   作者:neo_will_mvp  
這篇文章主要為大家詳細(xì)介紹了python2.7實(shí)現(xiàn)復(fù)制大量文件及文件夾資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

說(shuō)明: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) 

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

相關(guān)文章

  • python中watchdog文件監(jiān)控與檢測(cè)上傳功能

    python中watchdog文件監(jiān)控與檢測(cè)上傳功能

    這篇文章主要介紹了python中watchdog文件監(jiān)控與檢測(cè)上傳功能,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-10-10
  • python語(yǔ)言基本語(yǔ)句用法總結(jié)

    python語(yǔ)言基本語(yǔ)句用法總結(jié)

    在本篇文章里小編給大家整理了關(guān)于python語(yǔ)言基本語(yǔ)句的相關(guān)知識(shí)點(diǎn)以及實(shí)例代碼,需要的朋友們參考下。
    2019-06-06
  • Django 解決上傳文件時(shí),request.FILES為空的問題

    Django 解決上傳文件時(shí),request.FILES為空的問題

    這篇文章主要介紹了Django 解決上傳文件時(shí),request.FILES為空的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-05-05
  • Python實(shí)現(xiàn)的計(jì)算馬氏距離算法示例

    Python實(shí)現(xiàn)的計(jì)算馬氏距離算法示例

    這篇文章主要介紹了Python實(shí)現(xiàn)的計(jì)算馬氏距離算法,簡(jiǎn)單說(shuō)明了馬氏距離算法原理,并結(jié)合實(shí)例形式分析了Python實(shí)現(xiàn)與使用馬氏距離算法的相關(guān)操作技巧,需要的朋友可以參考下
    2018-04-04
  • 如何使用Python實(shí)現(xiàn)PPT批量轉(zhuǎn)圖片

    如何使用Python實(shí)現(xiàn)PPT批量轉(zhuǎn)圖片

    這篇文章主要為大家詳細(xì)介紹了如何使用Python開發(fā)一個(gè)帶有圖形界面的PPT批量轉(zhuǎn)圖片工具,文中的示例代碼講解詳細(xì),有需要的小伙伴可以了解下
    2025-02-02
  • django實(shí)現(xiàn)分頁(yè)的方法

    django實(shí)現(xiàn)分頁(yè)的方法

    這篇文章主要介紹了django實(shí)現(xiàn)分頁(yè)的方法,實(shí)例分析了django分頁(yè)的技巧與Paginator對(duì)象的用法,需要的朋友可以參考下
    2015-05-05
  • python里使用正則的findall函數(shù)的實(shí)例詳解

    python里使用正則的findall函數(shù)的實(shí)例詳解

    這篇文章主要介紹了python里使用正則的findall函數(shù)的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文能幫助到大家,需要的朋友可以參考下
    2017-10-10
  • python實(shí)現(xiàn)猜拳游戲

    python實(shí)現(xiàn)猜拳游戲

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)猜拳游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • django遷移文件migrations的實(shí)現(xiàn)

    django遷移文件migrations的實(shí)現(xiàn)

    這篇文章主要介紹了django遷移文件migrations的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • 查看python安裝路徑及pip安裝的包列表及路徑

    查看python安裝路徑及pip安裝的包列表及路徑

    這篇文章主要介紹了查看python安裝路徑及pip安裝的包列表及路徑,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-04-04

最新評(píng)論

大邑县| 留坝县| 林口县| 瓦房店市| 连城县| 莱西市| 攀枝花市| 调兵山市| 哈尔滨市| 吴江市| 平利县| 苍南县| 商丘市| 淮滨县| 德惠市| 额敏县| 广河县| 班戈县| 绥芬河市| 灵寿县| 陆良县| 滁州市| 太仆寺旗| 图木舒克市| 黑水县| 烟台市| 东乡| 永嘉县| 江达县| 贵阳市| 建湖县| 修武县| 昭通市| 仁化县| 海宁市| 临海市| 广德县| 明溪县| 阜城县| 湟中县| 区。|