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

首頁 > 編程 > Python > 正文

使用Python監(jiān)視指定目錄下文件變更的方法

2020-01-04 14:21:41
字體:
來源:轉載
供稿:網(wǎng)友

監(jiān)視指定目錄下文件變更。

# -*- coding: utf-8 -*-# @Author: xiaodong# @Date: just hide# @Last Modified by: xiaodong# @Last Modified time: just hideimport osimport globimport jsonimport datetimefrom typing import Iterable"""監(jiān)視指定目錄下文件變更"""def penetrate(root: os.path) -> Iterable: for ele in glob.glob(os.path.join(root, '*')): if os.path.isdir(ele):  yield ele  yield from penetrate(os.path.abspath(ele)) else:  yield eledef update(s: set, exists: bool=False, mode: str='w') -> None or dict : with open('file_records.json', encoding='utf-8', mode=mode) as file: if not exists:  json.dump({'datetime': str(datetime.datetime.now()),   'files': list(s)}, file, ensure_ascii=False, indent=10) else:  return json.load(file)def main(s: set=set(), root: os.path='.')-> None: for path in penetrate(root): s.add(path) if not os.path.exists('file_records.json'): update(s) else: d = update(None, True, 'r') files = s - set(d['files']) files2 = set(d['files']) - s if files:  print('增加文件: ', files) if files2:  print('刪除文件: ', files2) if files or files2:  update(s)  print('更新成功!')if __name__ == "__main__": main()

以上這篇使用Python監(jiān)視指定目錄下文件變更的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網(wǎng)。


注:相關教程知識閱讀請移步到python教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 峨边| 迭部县| 玉屏| 宁蒗| 宜兰市| 大石桥市| 乌恰县| 东安县| 红安县| 安宁市| 石城县| 邻水| 明溪县| 治多县| 唐河县| 黄平县| 恩施市| 新郑市| 昌都县| 白银市| 黎川县| 安溪县| 都江堰市| 喜德县| 沧源| 新营市| 平泉县| 邵武市| 福鼎市| 岐山县| 谢通门县| 剑川县| 文水县| 涡阳县| 宁阳县| 涞源县| 南宫市| 望谟县| 都江堰市| 宁陕县| 兴城市|