国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Python > 正文

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

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

本文實例為大家分享了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/

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通海县| 长治市| 连平县| 合山市| 双峰县| 博湖县| 沾益县| 镇平县| 禄丰县| 英超| 丹阳市| 吴堡县| 巧家县| 赣榆县| 临泉县| 林甸县| 新竹市| 团风县| 丹东市| 洮南市| 湛江市| 杭州市| 蒲江县| 南陵县| 梅河口市| 融水| 逊克县| 连州市| 瑞安市| 通辽市| 临邑县| 宜昌市| 江阴市| 新巴尔虎左旗| 甘孜| 广宗县| 吉首市| 上思县| 武功县| 屯门区| 牙克石市|