[python-win32] Why I get wrong filetime values with win32 api(FindFilesW) ?

Tim Roberts timr at probo.com
Thu May 11 18:43:28 CEST 2006


On Thu, 11 May 2006 09:47:54 +0200, Christian Stooker
<durumdara at mailpont.hu> wrote:

>Hi !
>
>As I say: interesting, because os.get*time functions get good result for 
>the files.
>  
>

They BOTH return good results.  They just use different time bases.

>####################################################
>import os,sys,win32file,win32api,time
>
>uFiles=win32file.FindFilesW(os.path.join(os.getcwd(),'*'))
>
>for uFile in uFiles:
>    fullfn=os.path.join(os.getcwd(),uFile[8])
>    #fullfn=win32api.GetShortPathName(fullfn)
>    #print [fullfn]
>    if os.path.isfile(fullfn):
>        print [fullfn]
>        w32modtime=uFile[3]
>        osmodtime=os.path.getmtime(fullfn)
>        print "pw32",int(w32modtime)
>        print "pyos",osmodtime
>        print "pw32",time.asctime((time.localtime(int(w32modtime))))
>        print "pyos",time.asctime((time.localtime(osmodtime)))
>####################################################
>      ...
>
>As you can see, the different is two hours.
>We are in GMT+01 timezone, and I use NTFS and WXP.
>

You are in CET, right?  That's nominally GMT+01, but you are currently
in summer time, which makes it GMT+02.

>I hope this help to find a bug, or get the solution.
>  
>

Mark told you the answer.  This is not a bug.  os.path.getmtime returns
your local time, and the FindFiles API returns GMT.  If you need to
compare the two, you will have to subtract your timezone offset:

   print "pw32",time.asctime(time.localtime(int(w32modtime)-time.altzone))

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-win32 mailing list