Home  >  Q&A  >  body text

How to modify the modification date of a file in python without changing the file

There is a requirement that I need to unify the modification time of all excels in the directory. I want to write a python script. At first I naively thought that renaming would be enough, but in fact it is not possible.
Then I found several libraries for operating excel (openpyxl, xlutils), and wanted to open and save them. The result was that either the xlsx format was not supported or the format was not supported. . In short, there are always some flaws in the format, which will destroy the original style. .
So is there any other way? The effect is equivalent to opening and saving this file (excel)

滿天的星座滿天的星座2646 days ago971

reply all(4)I'll reply

  • 漂亮男人

    漂亮男人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.

    reply
    0
  • ringa_lee

    ringa_lee2017-06-22 11:53:55

    shutil.copy

    reply
    0
  • 代言

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

    What kind of system is it? If it’s Linux, just touch it directly. You have to go through such trouble

    reply
    0
  • 给我你的怀抱

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

    Copy the source file, rename it, and then delete the source file.

    reply
    0
  • Cancelreply