python如何获得文件的元数据

元数据就是文件的大小与修改日期等信息。
D:\pythonWork>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.exists('cookbook_p104.py')
True
>>> os.path.abspath('cookbook_p104.py')
'D:\\pythonWork\\cookbook_p104.py'
>>> os.path.exists('D:\\pythonWork\\cookbook_p104.py')
True
>>> os.path.isfile('D:\\pythonWork\\cookbook_p104.py')
True
>>> os.path.isdir('D:\\pythonWork\\cookbook_p104.py')
False
>>> os.path.isdir('D:\\pythonWork')
True
>>> os.path.isfile('D:\\pythonWork')
False
>>> os.path.getsize('D:\\pythonWork\\cookbook_p104.py')
491
>>> import time
>>> time.ctime(os.path.gettime('D:\\pythonWork\\cookbook_p104.py'))
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: module 'ntpath' has no attribute 'gettime'
>>> time.ctime(os.path.getmtime('D:\\pythonWork\\cookbook_p104.py'))
'Thu Mar  8 10:01:33 2018'
>>>

你可能感兴趣的:(python如何获得文件的元数据)