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

查看:52
本文介绍了如何在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.

推荐答案

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

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天全站免登陆