How to read file attributes in directory?

后端 未结 2 1758
清歌不尽
清歌不尽 2020-12-17 16:43

For example,

import os
print os.listdir()

list files in directory.

How to get file modification time fo all files in directory ?

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 17:44

    If you only want the modified time, then os.path.getmtime(filename) will get it for you. If you are using listdir with an argument, you'll need to also use os.path.join:

    import os, os.path
    
    for filename in os.listdir(SOME_DIR):
        print os.path.getmtime(os.path.join(SOME_DIR, filename))
    

提交回复
热议问题