python 遍历文件并获得文件的修改时间

# -*- coding: utf-8 -*-
import os
import sys
import time

reload(sys)
sys.setdefaultencoding('utf8')


path = u"D:\VPN\代码\数据仓库存储过程修改备份"
for root, dir, files in os.walk(path):
    for file in files:
        full_path = os.path.join(root, file)
        #print(full_path)
        #print(file)
        mtime = os.stat(full_path).st_mtime
        file_modify_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(mtime))
        print("{0} 修改时间是: {1}".format(full_path,file_modify_time))

 

C:\Users\Administrator\Anaconda3\envs\lineage_relation\python.exe D:/python_project/test_db_python/svn_test/check_updated_svn_file.py
D:\VPN\代码\数据仓库存储过程修改备份\PKG_DIM\PKG_DIM_20180625_YJT_1.pck 修改时间是: 2018-06-25 18:15:53
D:\VPN\代码\数据仓库存储过程修改备份\PKG_DM\PKG_DM_20180709_LYL_1.pck 修改时间是: 2018-07-11 07:36:40
D:\VPN\代码\数据仓库存储过程修改备份\PKG_DM\PKG_DM_20180709_LYL_1.~pck 修改时间是: 2018-07-11 07:36:40

 

posted @ 2018-07-17 15:21  翱翔的孤鹰  阅读(19241)  评论(0编辑  收藏  举报