Heim  >  Fragen und Antworten  >  Hauptteil

So ändern Sie das Änderungsdatum einer Datei in Python, ohne die Datei zu ändern

Es besteht die Anforderung, dass ich die Änderungszeit aller Excel-Dateien im Verzeichnis vereinheitlichen muss. Zuerst dachte ich naiv, dass eine Umbenennung ausreichen würde, aber tatsächlich ist dies nicht möglich.
Dann habe ich mehrere Bibliotheken zum Betreiben von Excel gefunden (openpyxl, xlutils) und wollte sie öffnen und speichern. Das Ergebnis war, dass sie entweder das Lesen des XLSX-Formats nicht unterstützten, oder. . Kurz gesagt, es gibt immer einige Fehler im Format, die den ursprünglichen Stil zerstören. .
Gibt es also eine andere Möglichkeit? Der Effekt entspricht dem Öffnen und Speichern dieser Datei (Excel)

滿天的星座滿天的星座2646 Tage vor975

Antworte allen(4)Ich werde antworten

  • 漂亮男人

    漂亮男人2017-06-22 11:53:55

    os.utime

    Help on built-in function utime in module posix:
    
    utime(...)
        utime(path, (atime, mtime))
        utime(path, None)
    
        Set the access and modified time of the file to the given values.  If the
        second form is used, set the access and modified times to the current time.

    Antwort
    0
  • ringa_lee

    ringa_lee2017-06-22 11:53:55

    shutil.copy

    Antwort
    0
  • 代言

    代言2017-06-22 11:53:55

    是什么系统啊,如果是linux,直接touch不就好了,非要这么折腾

    Antwort
    0
  • 给我你的怀抱

    给我你的怀抱2017-06-22 11:53:55

    复制一份源文件再重命名,再删除源文件.

    Antwort
    0
  • StornierenAntwort