2005年07月01日 星期五 11:49
Jason Liu wrote: > 已经搞定了,利用os.utime函数 > > for root, dirs, files in os.walk(path):#得到遍历列表 > for file in files: > stat = os.stat(os.path.join(root, file)) > at = localtime(stat[ST_ATIME]) #last access time > mt = localtime(stat[ST_MTIME]) #last modify time > if mt[0] == 2024 and mt[1] >= 6 and mt[2] > 7: > #下面一段有点怪,不知道有没有更好的写法 > at_t = [at[i] for i in range(9)] 将tuple转为list: at_t = list(at) > #下面两行应该可以不要 > at_t[0] = 2005 > at_st = mktime(at_t) > mt_t = [mt[i] for i in range(9)] > mt_t[0] = 2005 > mt_st = mktime(mt_t) > #修改last modify time > os.utime(os.path.join(root, file), (at_st, mt_st)) > > 在 05-6-30,Jason Liu<telecomliu at gmail.com> 写道: > >>机器莫名其妙地跳到了2024年,等到我改正后已经有大量文件和目录的日期错误,给工作造成很大的麻烦。 >>请问python能否修改文件的日期,如何做? >>谢谢! >> -- Qiangning Hong _____________________________________________________________ ( An empty cab drove up and Sarah Bernhardt got out. -Arthur ) ( Baer, ) ( ) ( American comic and columnist ) ------------------------------------------------------------- o . _ . o |\_|/__/| / / \/ \ \ /__|O||O|__ \ |/_ \_/\_/ _\ | | | (____) | || \/\___/\__/ // (_/ || | || | ||\ \ //_/ \______// __ || __|| (____(____)
Zeuux © 2025
京ICP备05028076号