English 中文(简体)
更改/重整/进入时间的不一致
原标题:Inconsistency in modified/created/accessed time on mac

I m 正在使用os.utime,以正确确定Mac的修改时间(Mac OS X 10.6.2, dell/ 2.6.1 from /usr/bin/python)。 它不符合<代码>touch效用,不符合Finder s“get info”窗口展示的特性。

考虑以下指挥顺序。 平原案文中创造和修改的时代指的是“植被信息”窗口在发现器中的特性。 http://docs.python.org/library/os.html#os.utime”rel=“nofollow noreferer”>os.utime 。 论点<代码>(姓名,(时间,时间)

>>> import os
>>> open( tempfile , w ).close()

创造和修改都是目前时间。

>>> os.utime( tempfile , (1000000000, 1500000000) )

设定为目前时间,修改为2017年7月13日。

>>> os.utime( tempfile , (1000000000, 1000000000) )

2001年9月8日设立并修改。

>>> os.path.getmtime( tempfile )
1000000000.0
>>> os.path.getctime( tempfile )
1269021939.0
>>> os.path.getatime( tempfile )
1269021951.0

......os.path.get?time and os.stat 无。

>>> os.utime( tempfile , (1500000000, 1000000000) )

2001年9月8日创建和修改的still/em>。

>>> os.utime( tempfile , (1500000000, 1500000000) )

成立日期是2001年9月8日,修改为2017年7月13日。

我不敢肯定,这是否是一个棘手的问题或一个宏观问题。 当我离开沙尔,跑

touch -a -t 200011221234 tempfile

修改和设定时间都没有改变,如预期。 然后,我就跑了。

touch -m -t 200011221234 tempfile

并且,创造和修改的时间都发生了变化。

是否有任何想法? 我如何不断地改变对玉米的修改和创造时间? (Yes,我知道,在不完善的系统中,没有“创造时间”。)


运行 Chris Johnsen sscript:

seth@local:~$ /usr/bin/python timetest.py tempfile 5
initial:
(1269631281.0, 1269631281.0, 1269631281.0, 1269631281, 1269631281, 1269631281)

test: (1000000000, 1000000000)
(1000000000.0, 1000000000.0, 1269631281.0, 1000000000, 1000000000, 1269631281)
(1269631281.0, 1000000000.0, 1269631281.0, 1269631281, 1000000000, 1269631281)

test: (1000000000, 1500000000)
(1000000000.0, 1500000000.0, 1269631286.0, 1000000000, 1500000000, 1269631286)
(1269631286.0, 1500000000.0, 1269631286.0, 1269631286, 1500000000, 1269631286)

test: (1500000000, 1000000000)
(1500000000.0, 1000000000.0, 1269631291.0, 1500000000, 1000000000, 1269631291)
(1269631291.0, 1000000000.0, 1269631291.0, 1269631291, 1000000000, 1269631291)

test: (1500000000, 1500000000)
(1500000000.0, 1500000000.0, 1269631296.0, 1500000000, 1500000000, 1269631296)
(1269631296.0, 1500000000.0, 1269631296.0, 1269631296, 1500000000, 1269631296)

在这项工作结束时,发现者所看到的创建日期是9/8/01,修改日期是7/13/17。 (根据你的建议和我刚才所了解的情况,访问日期大致现在) 发现器中发现的经修改的日期仍然毫无意义。

最佳回答

POSIX atime, mtime, ctime

如果你包含一个完整的文字及其实际和预期产出,而不是REPL的碎块,就可能有所帮助。

import sys, os, stat, time

def get_times(p):
    s = os.stat(p)
    return ( 
        os.path.getatime(p),
        os.path.getmtime(p),
        os.path.getctime(p),
        s[stat.ST_ATIME],
        s[stat.ST_MTIME],
        s[stat.ST_CTIME],
    )

def main(p, delay=1):
    delay = float(delay)
    (a,b) = (1000000000, 1500000000)

    open(p, w ).close()

    print  initial: 
    print get_times(p)

    for t in [ (a,a), (a,b), (b,a), (b,b) ]:
        print
        print  test: , t
        os.utime(p,t)
        print get_times(p)
        time.sleep(delay)
        print get_times(p)

main(*sys.argv[1:])

我在我的10.4个系统上取得了这一成绩,有<条码>c d“$HOME” &&python 测试。 py tempfile 5 (系统系统故障2.3.6和MacPorts-030 2.6.4均得出相同结果(当然包括初始时间和 /m>):

% python /tmp/test.py tempfile 5
initial:
(1000000000.0, 1000000000.0, 1269629881.0, 1000000000, 1000000000, 1269629881)

test: (1000000000, 1000000000)
(1000000000.0, 1000000000.0, 1269629881.0, 1000000000, 1000000000, 1269629881)
(1000000000.0, 1000000000.0, 1269629881.0, 1000000000, 1000000000, 1269629881)

test: (1000000000, 1500000000)
(1000000000.0, 1500000000.0, 1269629886.0, 1000000000, 1500000000, 1269629886)
(1000000000.0, 1500000000.0, 1269629886.0, 1000000000, 1500000000, 1269629886)

test: (1500000000, 1000000000)
(1500000000.0, 1000000000.0, 1269629891.0, 1500000000, 1000000000, 1269629891)
(1500000000.0, 1000000000.0, 1269629891.0, 1500000000, 1000000000, 1269629891)

test: (1500000000, 1500000000)
(1500000000.0, 1500000000.0, 1269629896.0, 1500000000, 1500000000, 1269629896)
(1500000000.0, 1500000000.0, 1269629896.0, 1500000000, 1500000000, 1269629896)

这似乎是合理的。 我想知道你们会怎样做。

我听到,Spotlight有时会因重新编篡改变了的档案而积极地重新启用atime。 我并不期望它重新编制只经过了假日/假日的文件,但我相信这样做是可能的。 在Spotlight(例如/tmp/testfile)未编入索引的地点,消除可能复杂化的Spotlight。

Date Created in Finder

(在Finder信息窗口中称为“混合:”)

如果安装了开发工具,你可使用<代码>/Developer/Tools/GetFileInfo>/code>,看家事科的创建情况。 我在每条<代码>印本上加上以下线:

sys.stdout.flush()
os.system( /Developer/Tools/GetFileInfo   + p)

我也修改了标题,以与你的初始描述相一致([(a,b)、(a)、(a)、(b)、(b)、(b)])。

结果是:

% rm /tmp/tempfile; python /tmp/test.py /tmp/tempfile 1
initial:
(1269636574.0, 1269636574.0, 1269636574.0, 1269636574, 1269636574, 1269636574)
file: "/private/tmp/tempfile"
type: ""
creator: ""
attributes: avbstclinmedz
created: 03/26/2010 15:49:34
modified: 03/26/2010 15:49:34

test: (1000000000, 1500000000)
(1000000000.0, 1500000000.0, 1269636574.0, 1000000000, 1500000000, 1269636574)
file: "/private/tmp/tempfile"
type: ""
creator: ""
attributes: avbstclinmedz
created: 03/26/2010 15:49:34
modified: 07/13/2017 21:40:00
(1000000000.0, 1500000000.0, 1269636574.0, 1000000000, 1500000000, 1269636574)
file: "/private/tmp/tempfile"
type: ""
creator: ""
attributes: avbstclinmedz
created: 03/26/2010 15:49:34
modified: 07/13/2017 21:40:00

test: (1000000000, 1000000000)
(1000000000.0, 1000000000.0, 1269636576.0, 1000000000, 1000000000, 1269636576)
file: "/private/tmp/tempfile"
type: ""
creator: ""
attributes: avbstclinmedz
created: 09/08/2001 20:46:40
modified: 09/08/2001 20:46:40
(1000000000.0, 1000000000.0, 1269636576.0, 1000000000, 1000000000, 1269636576)
file: "/private/tmp/tempfile"
type: ""
creator: ""
attributes: avbstclinmedz
created: 09/08/2001 20:46:40
modified: 09/08/2001 20:46:40

test: (1500000000, 1000000000)
(1500000000.0, 1000000000.0, 1269636577.0, 1500000000, 1000000000, 1269636577)
file: "/private/tmp/tempfile"
type: ""
creator: ""
attributes: avbstclinmedz
created: 09/08/2001 20:46:40
modified: 09/08/2001 20:46:40
(1500000000.0, 1000000000.0, 1269636577.0, 1500000000, 1000000000, 1269636577)
file: "/private/tmp/tempfile"
type: ""
creator: ""
attributes: avbstclinmedz
created: 09/08/2001 20:46:40
modified: 09/08/2001 20:46:40

test: (1500000000, 1500000000)
(1500000000.0, 1500000000.0, 1269636578.0, 1500000000, 1500000000, 1269636578)
file: "/private/tmp/tempfile"
type: ""
creator: ""
attributes: avbstclinmedz
created: 09/08/2001 20:46:40
modified: 07/13/2017 21:40:00
(1500000000.0, 1500000000.0, 1269636578.0, 1500000000, 1500000000, 1269636578)
file: "/private/tmp/tempfile"
type: ""
creator: ""
attributes: avbstclinmedz
created: 09/08/2001 20:46:40
modified: 07/13/2017 21:40:00

这似乎与你在Finder<>>>/em>上的Gefo之窗的意见一致。 我的解释(通过其他试验传播)是,建立爱阵设施。 日期按时段更新,但只是向后(不管向往)。 如果你想要更新爱幼学校的创造价值,那么你很可能不得不使用一种针对特定对象的软件来这样做。

另有一份说明:您可能不得不将窗户转开,以便更新Get窗户。 在我的系统中,除非我把窗户转到或从GetInfo窗户,否则其显示不会自动更新。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...