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

首頁 > 開發 > Python > 正文

python定時復制遠程文件夾中所有文件

2024-09-09 19:02:08
字體:
來源:轉載
供稿:網友

本文實例為大家分享了python定時復制遠程文件夾中文件的具體代碼,供大家參考,具體內容如下

import os, shutil, sysimport threadingimport configparserimport datetime  #復制文件def remote_copy(src_path, dst_path):  start_time = datetime.datetime.now()print(start_time, " 開始復制……")bCopy = False;try:# 獲取源文件夾中的所有文件及文件夾files = os.listdir(src_path)for file in files:#生成絕對路徑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("無法發現文件,請檢查網絡連接!")os.system('pause')sys.exit()  else:if not bCopy:print("未發現新文件……")end_time = datetime.datetime.now()'''time = span - (end_time - start_time).secondsprint(end_time, " 本次執行完畢,等待", time, "秒……")'''  print(end_time, " 本次執行完畢,等待", span, "秒……") #定時復制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("執行間隔為 :", span)print("文件限制為 :", file_size)print("輸入文件夾為:", src_path)print("輸出文件夾為:", dst_path)  inp = input("是否繼續(y/n):")if inp == 'y' or inp == 'Y': timer = threading.Timer(1, timer_copy, [src_path, dst_path])timer.start()  #測試#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/

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久精品欧美视频 | 国产精品自拍av | 国产一区二区在线免费播放 | 久久爽精品区穿丝袜 | 亚洲一级片免费观看 | 欧美激情综合在线 | 国产午夜精品久久久 | 九九热免费在线观看 | 国产成视频在线观看 | 欧美一区二区三区免费观看 | 亚洲国产超高清a毛毛片 | 欧美aⅴ视频 | 成人免费乱码大片a毛片视频网站 | 精品亚洲va在线va天堂资源站 | 久久久久免费精品国产小说色大师 | 亚洲第一页综合 | 国产精品一区二区三区99 | 最新毛片在线观看 | 91热久久免费频精品黑人99 | 国产精品99久久久久久久女警 | 九九热免费精品 | 欧美爱爱视频 | 国产精品免费视频观看 | 国产精品成人一区二区三区电影毛片 | 久久里面有精品 | 中文字幕免费在线观看视频 | 九一免费版在线观看 | 毛片在线免费视频 | 欧美日韩在线视频一区 | 在线成人www免费观看视频 | 高清做爰免费无遮网站挡 | 久久精品艹 | 久久国产精品99国产 | 日日草夜夜操 | 一区二区三级视频 | 久久tv免费国产高清 | 国产中出在线观看 | 国产91久久精品 | 欧美aⅴ在线观看 | 在线免费观看日韩视频 | 久草在线观看福利 |