6

I need to update the creation time of a .mp4 file so that it will appear at the top of a list of media files sorted by creation date. I am able to easily update both the accessed and modified date of the file using os.utime, but have yet to find a good way to change the created date of a file to "now".

My end goal is to seed media files to an iOS simulator using appium, and have those media files accessible in that script. The issue is that the video file will not be displayed in the "recently added" section of the app because it is several days old.

Eric
  • 159
  • 2
  • 11

3 Answers3

3

I was able to successfully use the subprocess call command to change the creation date of the file with a shell command.

from subprocess import call

command = 'SetFile -d ' + '"05/06/2019 "' + '00:00:00 ' + complete_path
call(command, shell=True)
Eric
  • 159
  • 2
  • 11
  • access and last modified can be done by `os.utime(path,(atime, mtime))` - thats not enough for your problem? [os.utime](https://docs.python.org/3/library/os.html#os.utime) – Patrick Artner May 06 '19 at 19:09
  • No, in my case updating the access and modified time wasn't enough. The application was exclusively checking the creation time. – Eric May 07 '19 at 15:47
0

This will also do the trick and I find it a bit cleaner:

import os
os.system('SetFile -d "{}" {}'.format(date.strftime('%m/%d/%Y %H:%M:%S'), filePath))
dontic
  • 63
  • 5
  • `subprocessing` module is [preferred](https://stackoverflow.com/questions/44730935/advantages-of-subprocess-over-os-system) to `os.system`. – johan Dec 23 '21 at 23:21
0

Combining @Eric's subprocess call and @dontic's strftime with my way of string manipulation for copy-paste. Thank you two for the solution.

from subprocess import call    

command = 'SetFile -d "%s" "%s"' % (date.strftime('%m/%d/%Y %H:%M:%S'), filePath)
call(command, shell=True)
Ferris S
  • 1
  • 1