如何在Mac上使用python更改文件的创建日期? [英] How to change the creation date of file using python on a mac?

查看:99
本文介绍了如何在Mac上使用python更改文件的创建日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新.mp4文件的创建时间,以使其显示在按创建日期排序的媒体文件列表的顶部.我能够使用os.utime轻松更新文件的访问日期和修改日期,但还没有找到一种将文件的创建日期更改为现在"的好方法.

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".

我的最终目标是使用appium将媒体文件播种到iOS模拟器中,并在该脚本中访问这些媒体文件.问题是该视频文件已有数天的历史,因此不会在该应用程序的最近添加"部分中显示.

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.

推荐答案

我能够使用shell命令成功地使用subprocess调用命令来更改文件的创建日期.

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)

这篇关于如何在Mac上使用python更改文件的创建日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆