How to set creation file time on MacOS X

Recently, I downloaded a bunch of mp4 videos from my PS4 to create some longer form videos for YouTube with iMovie. Unfortunately, the files copied from the PS4 did not retain the original creation date and time. I was bummed because iMovie uses the creation date to sort the video clips stored in its import library.
I’m pretty sure that the PS4 stores this information with the file in the BSD operating system used on the PS4. For whatever reason, this information is lost and is not retained when copying these video files to a USB drive.
Instead, the PS4 creates the files using the current date and time of when they were copied to USB. However, the filename does includes the date and time of the PS4’s original file creation date. All is not lost. For example, one of the files is named “Grand Theft Auto V_20231021102822.mp4.” The 20231021102822 is the file’s original creation date, but it’s embedded in the filename. This is a pain in the ass, especially when you have a lot of these files and you need to depend on sorting the files by creation date.
If you’re using Linux, some of this may apply with touch, but some may not. For example, it may not be possible to set the birth time or btime in Linux. Then again, you won’t be using iMovie on Linux, so you may not encounter the same sorting problems as when using iMovie. On Linux, you’re likely to be using ShotCut. And yes, ShotCut is available for MacOS X.
Let’s explore recovering and setting the original creation date and time for these imported PS4 video files when using a Mac.
Before Getting Started / Liability Waiver / Assumption of Risk
This is a relatively deep dive tutorial and is designed for intermediate to experienced users who are comfortable running command line tools in UNIX, Linux and MacOS X. This article also expects that you are at least somewhat experienced and familiar with writing Bash shell scripts. While every care has been taken to ensure these instructions are fully accurate at the time of authorship, risk is always a possibility when running commands. Make sure you know what you’re doing and always proceed with caution when performing any shell commands.
Assumption of Risk: Should you follow any instructions provided in this tutorial, you do so at your own risk. This author and the Randocity blog holds no responsibility for how you use and/or misuse the information provided herein NOR does this author or Randocity hold any liability over any damage that may result directly or indirectly from this article’s included information. This information is provided to you AS IS. You assume all risks herein.
By proceeding with reading the remainder of this article, you agree to these terms. If you don’t agree with these terms, then navigate away NOW and go find something else to do.
Recovering Dates and Times on Files
There are two primary date/times stored as metadata with each file: creation date and last modified date. While it’s easy to set the last modification date using the ‘touch‘ command, this same command cannot be used to set the file’s creation time. Pity.
That left me looking for alternatives. If you have installed the command line development tools from Mac OS’s Xcode, there are a couple of handy command line (CLI) tools available to help with this date-setting task. These two tools are getfileinfo and setfile. Unfortunately, it seems that while the commands do get installed with Xcode, the manual pages (man pages) do not get installed. Thus, you can’t easily see or find the parameter usage of the command.
I had to refer to searching Google for the man pages for these two. Here’s the man page for getfileinfo. Here is the man page for setfile. These two commands will help get you started. If you don’t have these commands installed, you’ll need to install the Xcode command line tools.
First Step
Setting the last modification time from the above filename supplied is relatively easy by extracting the filename’s included datecode, slightly modifying it and feeding it back into the command ‘touch‘ to set the last modification date onto the file. Here’s a shell script which does just this on all files in the current directory:
#!/bin/bash
#
# setmodificationdate.sh
# FILE: "Grand Theft Auto V_20231021102822.mp4"
# DATECODE EXAMPLE: 20231021102822 => 202310211028.22
# Set IFS delimiter to EOL marker to ignore whitespace in filenames
IFS="
"
# Loop through files in current directory and update each file's last modification
# time to ${DATECODE}.${DATESS} using touch -mt [date]
for i in `ls`
do
FILE=$i
DATECODE=`echo "${FILE}" | awk '{print $4}' | awk -F "_" '{print $2}' | cut -c 1-12`
DATESS=`echo "${FILE}" | awk '{print $4}' | awk -F "_" '{print $2}' | cut -c 13-14`
# The touch command requires the date format to be YYYYMMDDHHMM.SS. Some
# conversion is required.
if [ $DATECODE ]; then
touch -mt ${DATECODE}.${DATESS} "$FILE"
echo $FILE ${DATECODE}.${DATESS} done
fi
done
The reason it’s important to update the files using the touch command first is that we’ll later use the getfileinfo command on these updated files to extract the modification date set with touch, making it easier to extract the date format which is used by the setfile command. Otherwise, if we don’t do this, we’ll have to spend a boatload of time reformatting that 20231021102822 string into the string format required by setfile. No, thanks.
Because I’m generally lazy when I see other easier formatting alternatives, I don’t wish to spend a full day of shell scripting on reformatting strings when I don’t have to. Since both the last modification and creation dates should be set identically, using two different commands is the easiest way to get these files back to their original dates.
Second Step
After having updated the last modification date of each of the video files using ‘touch‘, we’re halfway there. The other half is updating the creation date using the ‘setfile‘ command. Right now, even though the modification date is updated, the creation date is still set to the date and time when the file was copied from the PS4 onto the USB drive. I’m still at a loss why PS4’s Capture app does this. No reason to dwell on stupidity from Sony. Let’s move on.
If you would like to see the current creation date on the files, check it with following command:
$ ls -lhU -rwxrwxrwx 1 owner staff 334M Oct 21 20:10 Grand Theft Auto V_20220826114603_1.mp4 -rwxrwxrwx 1 owner staff 452M Oct 21 20:05 Grand Theft Auto V_20220918194930_1.mp4 -rwxrwxrwx 1 owner staff 390M Oct 21 20:04 Grand Theft Auto V_20220922235359_1.mp4 -rwxrwxrwx 1 owner staff 398M Oct 21 20:04 Grand Theft Auto V_20221002025349_1.mp4 -rwxrwxrwx 1 owner staff 347M Oct 21 20:03 Grand Theft Auto V_20221007034124_1.mp4 -rwxrwxrwx 1 owner staff 389M Oct 21 20:03 Grand Theft Auto V_20221013095807_1.mp4 -rwxrwxrwx 1 owner staff 1.3G Oct 21 20:00 Grand Theft Auto V_20221022131151_1.mp4 -rwxrwxrwx 1 owner staff 342M Oct 21 20:00 Grand Theft Auto V_20221113174109_1.mp4 -rwxrwxrwx 1 owner staff 55M Oct 21 20:00 Grand Theft Auto V_20221124014001_1.mp4 -rwxrwxrwx 1 owner staff 389M Oct 21 19:59 Grand Theft Auto V_20221211111225_1.mp4 -rwxrwxrwx 1 owner staff 288M Oct 21 19:59 Grand Theft Auto V_20221213064150_1.mp4 -rwxrwxrwx 1 owner staff 419M Oct 21 19:58 Grand Theft Auto V_20221223001116_1.mp4 -rwxrwxrwx 1 owner staff 414M Oct 21 19:58 Grand Theft Auto V_20221230055654_1.mp4 -rwxrwxrwx 1 owner staff 77M Oct 21 19:57 Grand Theft Auto V_20230108204052_1.mp4 -rwxrwxrwx 1 owner staff 427M Oct 21 19:57 Grand Theft Auto V_20230108210502_1.mp4 -rwxrwxrwx 1 owner staff 133M Oct 21 19:57 Grand Theft Auto V_20230114165648_1.mp4 -rwxrwxrwx 1 owner staff 471M Oct 21 19:56 Grand Theft Auto V_20230205042420_1.mp4 -rwxrwxrwx 1 owner staff 441M Oct 21 19:55 Grand Theft Auto V_20230222025805_1.mp4 -rwxrwxrwx 1 owner staff 424M Oct 21 19:54 Grand Theft Auto V_20230227022823_1.mp4 -rwxrwxrwx 1 owner staff 373M Oct 21 19:54 Grand Theft Auto V_20230307124853_1.mp4 -rwxrwxrwx 1 owner staff 420M Oct 21 19:53 Grand Theft Auto V_20230311090033_1.mp4
To see the last modification time set from above touch command, use the following:
$ ls -lh -rwxrwxrwx 1 owner staff 334M Aug 26 2022 Grand Theft Auto V_20220826114603_1.mp4 -rwxrwxrwx 1 owner staff 452M Sep 18 2022 Grand Theft Auto V_20220918194930_1.mp4 -rwxrwxrwx 1 owner staff 390M Sep 22 2022 Grand Theft Auto V_20220922235359_1.mp4 -rwxrwxrwx 1 owner staff 398M Oct 2 2022 Grand Theft Auto V_20221002025349_1.mp4 -rwxrwxrwx 1 owner staff 347M Oct 7 2022 Grand Theft Auto V_20221007034124_1.mp4 -rwxrwxrwx 1 owner staff 389M Oct 13 2022 Grand Theft Auto V_20221013095807_1.mp4 -rwxrwxrwx 1 owner staff 1.3G Oct 22 2022 Grand Theft Auto V_20221022131151_1.mp4 -rwxrwxrwx 1 owner staff 342M Nov 13 2022 Grand Theft Auto V_20221113174109_1.mp4 -rwxrwxrwx 1 owner staff 55M Nov 24 2022 Grand Theft Auto V_20221124014001_1.mp4 -rwxrwxrwx 1 owner staff 389M Dec 11 2022 Grand Theft Auto V_20221211111225_1.mp4 -rwxrwxrwx 1 owner staff 288M Dec 13 2022 Grand Theft Auto V_20221213064150_1.mp4 -rwxrwxrwx 1 owner staff 419M Dec 23 2022 Grand Theft Auto V_20221223001116_1.mp4 -rwxrwxrwx 1 owner staff 414M Dec 30 2022 Grand Theft Auto V_20221230055654_1.mp4 -rwxrwxrwx 1 owner staff 77M Jan 8 2023 Grand Theft Auto V_20230108204052_1.mp4 -rwxrwxrwx 1 owner staff 427M Jan 8 2023 Grand Theft Auto V_20230108210502_1.mp4 -rwxrwxrwx 1 owner staff 133M Jan 14 2023 Grand Theft Auto V_20230114165648_1.mp4 -rwxrwxrwx 1 owner staff 471M Feb 5 2023 Grand Theft Auto V_20230205042420_1.mp4 -rwxrwxrwx 1 owner staff 441M Feb 22 2023 Grand Theft Auto V_20230222025805_1.mp4 -rwxrwxrwx 1 owner staff 424M Feb 27 2023 Grand Theft Auto V_20230227022823_1.mp4 -rwxrwxrwx 1 owner staff 373M Mar 7 2023 Grand Theft Auto V_20230307124853_1.mp4 -rwxrwxrwx 1 owner staff 420M Mar 11 2023 Grand Theft Auto V_20230311090033_1.mp4
Note that once a file’s date is considered “too old”, the ls command no longer shows the time of the file, only the “MM DD YYYY” date. The time is still there on the file, but it’s simply not shown. With ls, this will have to do.
Extracting the Date for Setfile
To extract the date string format needed for setfile, we’ll use the getfileinfo command on the now touched files. That’s done with the following:
$ getfileinfo -m "Grand Theft Auto V_20231021102822.mp4" 10/21/2023 10:28:22
The getfileinfo -m command returns the last modified date string in the date string format “10/21/2023 10:28:22”, which is a properly formatted string to immediately use with setfile -d. Thankfully, we just set this date on the file above. This output string value from getfileinfo should match the date value in the filename. If the date value doesn’t match, the touch command above might not have worked correctly.
To set the creation date on the file, we will use the following:
$ setfile -d "10/21/2023 10:28:22" "Grand Theft Auto V_20231021102822.mp4"
The -d option is used to set the creation date on the file. This command only changes one file, though. Not very helpful since we’re needing to update a bunch of files all at once. To do this, we’ll need a shell script for batch changes.
#!/bin/bash
#
# setcreationdate.sh
# Set field separator to EOL marker to ignore whitespace in filenames
IFS="
"
# Loop through files in current directory
for i in `ls`
do
FILE=$i
# Extract properly formatted creation date using getfileinfo
FCREATEDATE=`getfileinfo -m ${FILE}`
# Update creation date using setfile with date extracted from getfileinfo
# above, stored in FCREATEDATE
setfile -d "${FCREATEDATE}" "${FILE}"
echo ${FILE} done
done
Both of these shell scripts have been tested and worked perfectly to update the creation and modification dates on all of my PS4 video files back to their original dates recorded.
How do I use the scripts?
To use the above scripts, simply copy and paste them into your favorite MacOS X editor such as ‘vi’ or TextEdit, then save each script to whatever name you like. I named them setmodificationdate.sh and setcreationdate.sh, respectively. You can name them however you like. To make the script executable, do this with the following command:
$ chmod 755 scriptname.sh
Do these scripts work with vFAT formatted drives?
Yes, they do. These tools will work with vFAT as well as HFS+.
Is this the only way to change file dates?
No, there are other ways. You can use tools like ‘uuencode’, ‘tar’, ‘cpio’ or maybe even ‘zip’ to create an archive backup, then modify the dates inside the backup, then restore the files with newly updated dates. This is more complicated. The above is a simpler solution than mucking about with backup and restore processes. However, this archive solution may be the only way forward on operating systems that don’t allow modification of the creation dates on live files.
Why do all of this?
The iMovie app has an import library. In this imported clip library, the sorting feature uses the creation date, not modification date to sort the files. To make sure iMovie can sort these files properly date ascending, the creation date must be set correctly. Because copying the files to USB from the PS4 reassigns the date the mp4 was copied to the USB, not the date it was originally created on the PS4, this makes sorting from oldest to newest in iMovie a big problem.
When attempting to create a new movie using PS4 clips in chronological order, not having correct datestamps on each file makes it a challenge to locate the correct clips in the iMovie library. To correct for this, setting the creation date stamps on all of the mp4 files allows iMovie to sort them in the correct order, rather than sorting them based on the random date they were copied to the USB drive.
Note that once you have updated the dates on the mp4 files, you’ll need to restart iMovie to make sure it sees the newly updated dates on the files. iMovie won’t see these file changes until it’s been restarted.
Good luck and happy rendering!
↩︎






leave a comment