久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='EtboH'><style id='EtboH'><dir id='EtboH'><q id='EtboH'></q></dir></style></legend>
      <bdo id='EtboH'></bdo><ul id='EtboH'></ul>
      <i id='EtboH'><tr id='EtboH'><dt id='EtboH'><q id='EtboH'><span id='EtboH'><b id='EtboH'><form id='EtboH'><ins id='EtboH'></ins><ul id='EtboH'></ul><sub id='EtboH'></sub></form><legend id='EtboH'></legend><bdo id='EtboH'><pre id='EtboH'><center id='EtboH'></center></pre></bdo></b><th id='EtboH'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EtboH'><tfoot id='EtboH'></tfoot><dl id='EtboH'><fieldset id='EtboH'></fieldset></dl></div>
      1. <tfoot id='EtboH'></tfoot>

        <small id='EtboH'></small><noframes id='EtboH'>

      2. windows下用python修改文件創建/訪問/寫入時間戳

        Modify file create / access / write timestamp with python under windows(windows下用python修改文件創建/訪問/寫入時間戳)
        <i id='sNg4N'><tr id='sNg4N'><dt id='sNg4N'><q id='sNg4N'><span id='sNg4N'><b id='sNg4N'><form id='sNg4N'><ins id='sNg4N'></ins><ul id='sNg4N'></ul><sub id='sNg4N'></sub></form><legend id='sNg4N'></legend><bdo id='sNg4N'><pre id='sNg4N'><center id='sNg4N'></center></pre></bdo></b><th id='sNg4N'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='sNg4N'><tfoot id='sNg4N'></tfoot><dl id='sNg4N'><fieldset id='sNg4N'></fieldset></dl></div>
        1. <tfoot id='sNg4N'></tfoot>

            <legend id='sNg4N'><style id='sNg4N'><dir id='sNg4N'><q id='sNg4N'></q></dir></style></legend>

              <small id='sNg4N'></small><noframes id='sNg4N'>

                <tbody id='sNg4N'></tbody>
                <bdo id='sNg4N'></bdo><ul id='sNg4N'></ul>

                • 本文介紹了windows下用python修改文件創建/訪問/寫入時間戳的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我試圖找到一種在windows下使用python修改文件時間戳的簡單方法,但是網上沒有太多明確的信息.經過一段時間的搜索,我得到了解決方案.為了縮短對其他人的搜索,代碼如下.

                  I tried to find an easy way to modifiy a file timestamp under windows using python, but there was not much clear information on the web. After searching a while I got a solution. To shorten the search for others, the code follows here.

                  它可能會更簡單、更美觀,但它確實有效.我唯一沒有解決的是夏季時間 - 冬季時間問題,即如果給出夏季時間,結果會相差一小時.也許有人可以添加更正?

                  It might be done easier and more beautiful, but it works. The only thing I didn't solve is the summer time - winter time issue, i.e. if a time in summer is given, the result differs by one hour. Maybe someone can add a correction?

                  from win32file import CreateFile, SetFileTime, GetFileTime, CloseHandle 
                  from win32file import GENERIC_READ, GENERIC_WRITE, OPEN_EXISTING
                  from pywintypes import Time
                  import time
                  
                  import sys
                  import os
                  
                  if len(sys.argv)<5:
                    pfile = os.path.basename(sys.argv[0])
                    print "USAGE:
                  	%s <createTime> <modifyTime> <accessTime> <FileName>
                  " % pfile
                    print "EXAMPLE:"
                    print '%s "01.01.2000 00:00:00" "01.01.2000 00:00:00" "01.01.2000 00:00:00" file' % (pfile) 
                    sys.exit()  
                  
                  # get arguments  
                  cTime = sys.argv[1] # create
                  mTime = sys.argv[2] # modify
                  aTime = sys.argv[3] # access
                  fName = sys.argv[4]
                  
                  # specify time format
                  format = "%d.%m.%Y %H:%M:%S"
                  offset = 0 # in seconds
                  
                  # create struct_time object
                  cTime_t = time.localtime(time.mktime(time.strptime(cTime,format))+offset)
                  mTime_t = time.localtime(time.mktime(time.strptime(mTime,format))+offset)
                  aTime_t = time.localtime(time.mktime(time.strptime(aTime,format))+offset)
                  
                  # visually check if conversion was ok
                  print
                  print "FileName: %s" % fName
                  print "Create  : %s --> %s OK" % (cTime,time.strftime(format,cTime_t))
                  print "Modify  : %s --> %s OK" % (mTime,time.strftime(format,mTime_t))
                  print "Access  : %s --> %s OK" % (aTime,time.strftime(format,aTime_t))
                  print
                  
                  # change timestamp of file
                  fh = CreateFile(fName, GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_EXISTING, 0, 0) 
                  createTime, accessTime, modifyTime = GetFileTime(fh) 
                  print "Change Create from",createTime,"to %s" % (time.strftime(format,cTime_t))
                  print "Change Modify from",modifyTime,"to %s" % (time.strftime(format,mTime_t))
                  print "Change Access from",accessTime,"to %s" % (time.strftime(format,aTime_t))
                  print
                  
                  createTime = Time(time.mktime(cTime_t))
                  accessTime   = Time(time.mktime(aTime_t))
                  modifyTime    = Time(time.mktime(mTime_t))
                  SetFileTime(fh, createTime, accessTime, modifyTime) 
                  CloseHandle(fh)
                  
                  # check if all was ok
                  ctime = time.strftime(format,time.localtime(os.path.getctime(fName)))
                  mtime = time.strftime(format,time.localtime(os.path.getmtime(fName)))
                  atime = time.strftime(format,time.localtime(os.path.getatime(fName)))
                  
                  print "CHECK MODIFICATION:"
                  print "FileName: %s" % fName
                  print "Create  : %s" % (ctime)
                  print "Modify  : %s" % (mtime)
                  print "Access  : %s" % (atime)
                  

                  推薦答案

                  您可能需要在兩個地方更正冬/夏一小時的差異.在這兩種情況下,我們都使用 tm_isdst 字段,time.localtime 可以方便地計算出 夏令時 (DST)對特定時間戳有效.

                  There are two places where you might want to correct for winter/summer difference of one hour. In both cases, we make use of the tm_isdst field, which time.localtime conveniently calculates to tell us whether Daylight Savings Time (DST) was in effect for a particular timestamp.

                  如果您在夏季設置冬季時間戳,反之亦然,除非您在調用 SetFileTime 之前進行補償,否則它將在其匹配季節到來時關閉一個小時:

                  If you are setting a winter timestamp during summer, or vice versa, it will become off by an hour when its matching season comes around unless you compensate before calling SetFileTime:

                  now = time.localtime()
                  createTime = Time(time.mktime(cTime_t) + 3600 * (now.tm_isdst - cTime_t.tm_isdst))
                  accessTime = Time(time.mktime(aTime_t) + 3600 * (now.tm_isdst - aTime_t.tm_isdst))
                  modifyTime = Time(time.mktime(mTime_t) + 3600 * (now.tm_isdst - mTime_t.tm_isdst))
                  SetFileTime(fh, createTime, accessTime, modifyTime) 
                  

                  輸出校正

                  為了使 Python 報告與 Windows 資源管理器匹配,我們在調用 strftime 之前應用更正:

                  # check if all was ok
                  now = time.localtime()
                  ctime = os.path.getctime(fName)
                  mtime = os.path.getmtime(fName)
                  atime = os.path.getatime(fName)
                  ctime += 3600 * (now.tm_isdst - time.localtime(ctime).tm_isdst)
                  mtime += 3600 * (now.tm_isdst - time.localtime(mtime).tm_isdst)
                  atime += 3600 * (now.tm_isdst - time.localtime(atime).tm_isdst)
                  ctime = time.strftime(format,time.localtime(ctime))
                  mtime = time.strftime(format,time.localtime(mtime))
                  atime = time.strftime(format,time.localtime(atime))
                  

                  兩個更正

                  請注意,如果您同時應用兩者,您的 Python 輸出將再次與您的輸入不匹配.這可能是可取的(見下文),但如果它困擾您:

                  Both Corrections

                  Beware, if you apply both, your Python output will again seem to mismatch your input. This may be desirable (see below), but if it bothers you:

                  • 如果您更喜歡與一年中的原始時間相同的時間戳,請僅選擇 輸入更正.
                  • 僅選擇輸出校正,如果您習慣于在 DST 生效后一年兩次看到它們跳一小時然后消失.
                  • Choose only Input Correction if you prefer timestamps that look right at their native time of year.
                  • Choose only Output Correction if you're used to seeing them jump an hour twice a year as DST takes effect and then goes away.

                  Python 和 Windows 選擇了不同的方法在 UTC 和本地時區之間轉換時間戳:

                  Python and Windows have chosen different methods to convert timestamps between UTC and the local time zone:

                  • Python 使用在時間戳有效的 DST 代碼.這樣,時間戳全年都有一致的表示.

                  • Python uses the DST code that was in effect at the timestamp. This way, the time stamp has a consistent representation year-round.

                  Windows 使用現在生效的 DST 代碼.這樣,顯示的所有時間戳都具有相同的隱式代碼.

                  Windows uses the DST code in effect right now. This way, all time stamps shown have the same implicit code.

                  如果您使用 '%Z' 在轉換后的字符串中包含時區(例如 PST 與 PDT),這一點很明顯,但由于大多數應用程序(包括 Windows 資源管理器)不這樣做,明顯的一小時不一致可能清單.

                  This is evident if you use '%Z' to include the time zone in the converted string (PST vs. PDT, for example) but since most apps (including Windows Explorer) do not, an apparent one-hour inconsistency can manifest.

                  當使用明確的時間碼打印時,很明顯每列中的標記確實都代表同一時間:

                  When printed with explicit time codes, it becomes clear that the stamps in each column really do all represent the same instant in time:

                  File #1 (January)        File #2 (June)
                  2000-01-30 20:00:00 UTC  2000-06-22 20:00:00 UTC
                  
                  observed in January in California:
                  2000-01-30 12:00:00 PST  2000-06-30 13:00:00 PDT  [Python]
                  2000-01-30 12:00:00 PST  2000-06-30 12:00:00 PST  [Windows]
                  
                  observed in June in California:
                  2000-01-30 12:00:00 PST  2000-06-30 13:00:00 PDT  [Python]
                  2000-01-30 13:00:00 PDT  2000-06-30 13:00:00 PDT  [Windows]
                  
                  observed in June in New York:
                  2000-01-30 15:00:00 EST  2000-06-30 16:00:00 EDT  [Python]
                  2000-01-30 16:00:00 EDT  2000-06-30 16:00:00 EDT  [Windows]
                  

                  如果我們可以要求 strftime 遵守 tm_isdst 字段,以匹配 Windows 資源管理器和大多數其他顯示文件時間戳的應用程序,那就太好了,但至少有一個簡單的解決方法可以自己進行計算.

                  It would be nice if we could ask strftime to honor the tm_isdst field, to match Windows Explorer and most other apps that display file timestamps, but at least there's a simple workaround to do the calculation ourselves.

                  def adjustForDST (seconds):
                      now = time.localtime()
                      correction = 60*60 * (now.tm_isdst - time.localtime(seconds).tm_isdst)
                      return seconds + correction
                  
                  time.strftime(format, time.localtime(adjustforDST(mtime)))
                  

                  來源:

                  http://bytes.com/topic/python/answers/655606-python-2-5-1-broken-os-stat-modulehttp://search.cpan.org/~shay/Win32-UTCFileTime-1.58/lib/Win32/UTCFileTime.pm

                  如果 cpan 鏈接再次因新修訂而中斷,請按以下方式查找:

                  If the cpan link breaks again with a new revision, find it this way:

                  https://www.google.com/search?q=UTCFileTime.pm

                  這篇關于windows下用python修改文件創建/訪問/寫入時間戳的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)

                    <legend id='Q7TnQ'><style id='Q7TnQ'><dir id='Q7TnQ'><q id='Q7TnQ'></q></dir></style></legend>
                    <i id='Q7TnQ'><tr id='Q7TnQ'><dt id='Q7TnQ'><q id='Q7TnQ'><span id='Q7TnQ'><b id='Q7TnQ'><form id='Q7TnQ'><ins id='Q7TnQ'></ins><ul id='Q7TnQ'></ul><sub id='Q7TnQ'></sub></form><legend id='Q7TnQ'></legend><bdo id='Q7TnQ'><pre id='Q7TnQ'><center id='Q7TnQ'></center></pre></bdo></b><th id='Q7TnQ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Q7TnQ'><tfoot id='Q7TnQ'></tfoot><dl id='Q7TnQ'><fieldset id='Q7TnQ'></fieldset></dl></div>

                      <tfoot id='Q7TnQ'></tfoot>

                        <tbody id='Q7TnQ'></tbody>

                        • <bdo id='Q7TnQ'></bdo><ul id='Q7TnQ'></ul>

                          <small id='Q7TnQ'></small><noframes id='Q7TnQ'>

                          1. 主站蜘蛛池模板: 欧美一级一区 | 在线日韩欧美 | 一区二区三区欧美在线观看 | 欧美v日韩v | 国产成人一区二区三区精 | 给我免费的视频在线观看 | av特级毛片 | 中文字幕亚洲欧美 | 国产黄色小视频在线观看 | 欧美午夜精品 | 国产精品久久 | 国产高清在线视频 | 精品国产乱码 | 一级一片在线观看 | 国产91亚洲精品 | 午夜一区二区三区视频 | 乳色吐息在线观看 | 精品欧美一区二区在线观看视频 | 国产一区二区日韩 | 免费在线观看成年人视频 | av中文字幕网站 | 综合色久 | 亚洲免费在线 | 高清欧美性猛交 | 涩爱av一区二区三区 | 国产在线中文字幕 | 色婷婷激情 | 日韩精品一区二区三区高清免费 | 精品国产91乱码一区二区三区 | 亚洲一区二区三区桃乃木香奈 | 狠狠狠干 | 久久精品成人热国产成 | 永久免费在线观看 | 伊人精品在线 | 中文字幕av一区 | 九九导航 | 久久久久国产精品 | 精品国产免费人成在线观看 | 日本a网站 | 欧美日韩国产在线观看 | 激情五月激情综合网 |