麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 開發(fā) > Python > 正文

python定時(shí)復(fù)制遠(yuǎn)程文件夾中所有文件

2024-09-09 19:02:09
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例為大家分享了python定時(shí)復(fù)制遠(yuǎn)程文件夾中文件的具體代碼,供大家參考,具體內(nèi)容如下

import os, shutil, sysimport threadingimport configparserimport datetime  #復(fù)制文件def remote_copy(src_path, dst_path):  start_time = datetime.datetime.now()print(start_time, " 開始復(fù)制……")bCopy = False;try:# 獲取源文件夾中的所有文件及文件夾files = os.listdir(src_path)for file in files:#生成絕對(duì)路徑src_file = os.path.join(src_path,file)# 判斷是否為文件if os.path.isfile(src_file) and (os.path.getsize(src_file) < file_size) : dst_file = os.path.join(dst_path,file)if not os.path.exists(dst_file):bCopy = Trueshutil.copyfile(src_file, dst_file)'''copy_cmd = 'xcopy /D %s %s'%(src_file,dst_file)os.popen(copy_cmd)'''print(src_file, ' => ', dst_file, 'copy done!')#else:# print(dst_file, "已存在!")  except Exception as e:print("無(wú)法發(fā)現(xiàn)文件,請(qǐng)檢查網(wǎng)絡(luò)連接!")os.system('pause')sys.exit()  else:if not bCopy:print("未發(fā)現(xiàn)新文件……")end_time = datetime.datetime.now()'''time = span - (end_time - start_time).secondsprint(end_time, " 本次執(zhí)行完畢,等待", time, "秒……")'''  print(end_time, " 本次執(zhí)行完畢,等待", span, "秒……") #定時(shí)復(fù)制def timer_copy(src_path, dst_path):remote_copy(src_path, dst_path)  global timertimer = threading.Timer(span, timer_copy, [src_path, dst_path])timer.start()  # 程序入口if __name__ == "__main__":  #讀取配置文件config = configparser.ConfigParser()config.read("config.ini") src_path = config.get('path', 'srcPath')dst_path = config.get('path', 'dstPath')global spanspan = config.getint('run', 'timeSpan')global file_sizefile_size = config.getint('run', 'fileSize')  # 目的路徑不存在則建立路徑if not os.path.exists(dst_path):os.makedirs(dst_path)  print("配置文件為 :config.ini")print("執(zhí)行間隔為 :", span)print("文件限制為 :", file_size)print("輸入文件夾為:", src_path)print("輸出文件夾為:", dst_path)  inp = input("是否繼續(xù)(y/n):")if inp == 'y' or inp == 'Y': timer = threading.Timer(1, timer_copy, [src_path, dst_path])timer.start()  #測(cè)試#remote_copy(src_path, dst_path)else:sys.exit()

配置文件config.ini

[run]timeSpan=20000fileSize=5000[path]srcPath=//192.168.0.108/xxxx/dstPath=f:/downloads/

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

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 一级黄色在线免费观看 | 国产亚洲欧美日韩高清 | 精品一二三区视频 | 亚洲午夜在线视频 | 国产免费久久久久 | 手机视频在线播放 | 久久中文免费 | 久久精品中文字幕一区二区三区 | 欧美自拍三区 | 久久精品成人影院 | 国产精品久久久久久久久久10秀 | 亚洲九九色 | 狠狠干五月天 | 法国性xxx精品hd | 国产一国产一级毛片视频在线 | 久久福利小视频 | 成人福利免费在线观看 | 欧美成人精品h版在线观看 国产一级淫片在线观看 | 久久午夜国产 | 亚洲国产精品高潮呻吟久久 | 91精品国产综合久久婷婷香 | 福利一区二区三区视频在线观看 | 免看黄大片aa | 久久国语对白 | 青青国产在线视频 | 国产精品一区在线观看 | 精品亚洲一区二区三区 | 毛片av网| 中文字幕一区二区三区久久 | 把娇妻调教成暴露狂 | 久久一级 | www噜噜偷拍在线视频 | chinese乱子伦xxxx国语对白 | 久久密 | 久草在线高清视频 | 国产精品爆操 | 久久国产中文字幕 | 亚洲精品一区国产精品丝瓜 | 国产乱淫av | 日韩欧美电影一区二区三区 | 亚洲一区二区不卡视频 |