os.path 模块

import os
import time

# os.path 获取文件属性

# file = 'ped.png'
# print(os.path.abspath(file))
#
#
# print(os.path.getctime(file))      # os.path.getctime() 获取文件创建时间
# print(os.path.getatime(file))      # os.path.getatime() 文件最近访问时间
# print(os.path.getmtime(file))      # os.path.getmtime() 文件最近修改时间
#
# print(time.gmtime(os.path.getmtime(file)))
# print(os.path.getsize(file))
# print(os.path.normpath(file))


file = 'C:/learn/note.txt'
print(os.path.basename(file))
print(os.path.dirname(file))
print(os.path.split(file))
print(os.path.join('root','test','a.txt'))

os.path 模块的程序可以是遍地可见了。

参考:http://www.runoob.com/python3/python3-os-path.html

原文地址:https://www.cnblogs.com/TreeDream/p/10114031.html