以下脚本创建一个文本文件,并尝试以不同的方式更改stat.st_ctime
:
# -*- coding: UTF-8 -*-
import platform
import time
import os.path
print(platform.platform())
print(platform.machine())
print(platform.python_version())
fn = 'Hanswurst.txt'
if os.path.exists(fn):
print('Leaving. File already exist.')
quit()
file = open(fn, 'w')
file.close()
print('\nCreation time:')
print(time.ctime(os.stat(fn).st_ctime))
time.sleep(3)
os.utime(fn, None)
print('\nCreation time after call of utime. I guess this is ok:')
print(time.ctime(os.stat(fn).st_ctime))
time.sleep(3)
file = open(fn, 'w')
file.write('Hanswurst is dead.')
file.close()
print('\nBut also after another file with the same name is created ctime stays the same:')
print(time.ctime(os.stat(fn).st_ctime))
time.sleep(3)
os.remove(fn)
print('\nFile does exist?', os.path.exists(fn))
file = open(fn, 'w')
file.write('Hanswurst is dead.')
file.close()
print('\nEven if the file is deleted before ctime stays the same:')
print(time.ctime(os.stat(fn).st_ctime))
os.remove(fn)
在我的Windows 7机器上,64位Python 3.2创建了以下输出:
^{pr2}$为什么stat.st_ctime
从未改变过?如果我以后再开始写剧本,这也是真的。我要怎么做才能改变它?在
目前没有回答
相关问题 更多 >
编程相关推荐