""Martin v. Löwis"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> I created a file and specifically set the created date, last accessed >> date >> and last write date to >> >> 01/02/2003 12:34:56 > > How did you do that?
I used a "touch" utility to set the dates but let's try it a different way. Let's use Python 2.5.1 to set the timestamps ---->> set file timestamp import pywintypes import win32file import sys file_name = sys.argv[1] new_timestamp = pywintypes.Time([2003, 1, 2, 12, 34, 56]) f = win32file.CreateFile(file_name, win32file.GENERIC_WRITE, 0, None, win32file.OPEN_EXISTING, 0, 0) win32file.SetFileTime(f, new_timestamp, new_timestamp, new_timestamp) f.Close() Next I created an empty file with notepad. Then I used the above code to set the 3 timestamps. Let's confirm that Windows has the timestamps set to what we set them too. Here are the timestamps as reported by Windows: dir /tc joe.txt 01/02/2003 12:34 PM 0 joe.txt dir /ta joe.txt 01/02/2003 12:34 PM 0 joe.txt dir /tw joe.txt 01/02/2003 12:34 PM 0 joe.txt Looks like the python code worked to correctly set the timestamps (Note you can also verify them using properties on the file in Windows Explorer) Here is some python code to print out the timestamps: import os import stat import sys import time file_name = sys.argv[1] file_stats = os.stat(file_name) print 'Creation Time: %s' % time.strftime('%m/%d/%Y %H:%M:%S', time.localtime(file_stats[stat.ST_CTIME])) print 'Last Access Time: %s' % time.strftime('%m/%d/%Y %H:%M:%S', time.localtime(file_stats[stat.ST_ATIME])) print 'Last Write Time: %s' % time.strftime('%m/%d/%Y %H:%M:%S', time.localtime(file_stats[stat.ST_MTIME])) Now let's see what Python 2.4.2 says about the file Creation Time: 01/02/2003 12:34:56 Last Access Time: 01/02/2003 12:34:56 Last Write Time: 01/02/2003 12:34:56 Looks like Python 2.4.2 is reporting the timestamps correctly Now let's see what Python 2.5.1 says Creation Time: 01/02/2003 11:34:56 Last Access Time: 01/02/2003 11:34:56 Last Write Time: 01/02/2003 11:34:56 All times are off by 1 hour! Let's re-verify that Windows still says the timestamps are 01/02/2003 12:34:56. dir /tc joe.txt 01/02/2003 12:34 PM 0 joe.txt dir /ta joe.txt 01/02/2003 12:34 PM 0 joe.txt dir /tw joe.txt 01/02/2003 12:34 PM 0 joe.txt Windows still says the times are what we set them too. Opening up Windows Explorer also confirms that the times are still 01/02/2003 12:34:56. My text editor has a was to display the file names and timestamp info just like a dir command Let's see what it says: h: joe .txt 0 1/02/03 12:34 \ The text editor is reporting the correct timestamps too. So far everything else I try seems to report the timestamps correctly except for Python 2.5.1. It is difficult for me to believe that EVERYTHING else is wrong and Python 2.5.1 is correct, especially when you consider the fact that the code in Python 2.5.1 that performs this functionality is not the same code that was used in previous Python versions. Normally if something is not working, the biggest suspect is the last thing changed. In my other msg I posted a program that compares the timestamps of a dir /tc, dir /ta, and dir /tw for all files against what Python is reporting. This allows us to easily verify what Windows says the timestamps are versus what Python says they are. Python 2.4.2 ALWAYS got it correct. Python 2.5.1 gets it wrong as much as 50% of the time. So unless you are saying that Windows is wrong, Python 2.5.1 has to be wrong since it does not compare to what Windows reports. Since everything else I have tried matches what Windows reports that leads me to believe that Python 2.5.1 has to be wrong. >> I even found situations where the python timestamp was 1 minute later. >> (I >> know about the 2 second timestamps on FAT, all my filesystems are NTFS). >> I >> just found a situation where the python timestamp was 02:51 PM and the >> windows timestamp was 02:12 PM. DST or timezone changes are not going >> to >> make the results be off by 39 minutes? (My timezone is GMT - 5:00). > > Right. If that is reproducable, it is a bug. Please create a zip file > containing this file, and submit a bug report to sf.net/projects/python. Please see my other msg, I ran the program in that msg against the Python\lib directory: I tried it on multiple machines and found the same problems occurring. I already submitted a bug report with the sample code that demonstrates the problem. All Python 2.4.2 timestamps match what Windows reports The Python 2.5.1 timestamps vary Sometimes python is +1 minute Sometimes python is -1 hour Sometimes python is +59 minutes Sometimes python is +42 minutes Sometimes python is +37 minutes Sometimes python +2 minutes Sometimes python +30 minutes Sometimes python +3 minutes Sometimes python +33 minutes There is no way a timezone difference could explain those variations. Bottom line is that Python should be reporting what Windows reports. Even if it turns out that Windows has a bug and is wrong I still think that Python should be reporting the same thing because what Windows reports is what is expected. If Python reports something different (even if it was correct) the information is not useful if it differs from what everything else is reporting. I hope I have provided enough information for you to reproduce the bug so that a solution can be found. Thanks for your time investigating this.
-- http://mail.python.org/mailman/listinfo/python-list