How to read all new files of a directory with python?

前端 未结 1 836
甜味超标
甜味超标 2021-01-26 17:33

I\'m beginner in Python and I\'m wondering to know how can I add a condition in this code to read only all new files of .../data/ directory (for example from 24 hou

1条回答
  •  别那么骄傲
    2021-01-26 18:28

    for filename in glob.glob(os.path.join(path, '*.xml')):
        if os.path.getmtime(filename) < time.time() - 24 * 60 * 60:  # 24h ago
            continue  # skip the old file
        ...
    

    0 讨论(0)
提交回复
热议问题