I have a folder with several hundred video files. All files names are in this format:

2011-08-27 11.18.00

Unfortunately the 'Date Created' for each file is the date on which it were converted (a date in 2014), not the date it was originally taken (specified in the file name).

I've found that the touch -t operator can be used to change the creation date of a single file.

enter image description here

Below: file on which I've successfully changed the Date Created (with above command) and file for which Date Created is still incorrect.

enter image description here

Can anyone help with terminal code that would extract YYYYMMDDhhmm info from each file name and use it for the for the touch -t operation for that file, in a batch operation?

I'd like the creation date / time to be correct so that when I import into my library each file will be in the right place in the timeline.

Mac OS: El Capitan 10.11.5

Terminal Version: 2.6.1

Thanks all.

1 Answer 1

  • open Terminal
  • type cd (including the trailing space) and drag the folder containing the files to be renamed into the Terminal window (the folder is probably Desktop/PRIMARYVIDEOS, so the command should look like cd /Users/Andrew/Desktop/PRIMARYVIDEOS)
  • press Enter
  • type (or copy/paste)

    for f in *; do t=$(echo $f | sed -E 's/[-. mov]//g'); echo touch -t $t "$f"; done
  • press Enter
  • if (and only if) this results in a list of touch commands which look ok, type (or copy/paste)

    for f in *; do t=$(echo $f | sed -E 's/[-. mov]//g'); touch -t $t "$f"; done
  • press Enter
  • @andyp Looks good, give it a try :-)
    – nohillside
    Commented Jul 10, 2016 at 9:59
  • Hi @patrix We're getting somewhere! You're first bit of code on four files in a test folder ended up with something like this for each: touch -t 20110107141300 2011-01-07 14.13.00.mov. However, when running the second line of code after this I got this error for each: touch: out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS] The file names go down to the second, which touch can't deal with. The top bit of code hasn't snipped off the information about the seconds, which I think has caused the error
    – Andy P
    Commented Jul 10, 2016 at 10:01
  • If it helps @patrix, it looks like the seconds information in each file name is always 00 (so each file name always look like this: YYYY-MM-DD hh.mm.00.mov)
    – Andy P
    Commented Jul 10, 2016 at 10:19
  • Hi @patrix - I took off the information in the filename about the seconds for each of my four test files (e.g. so first code now produces: touch -t 201101071413 2011-01-07 14.13.mov) and the above code works PERFECTLY! Is there a way to tweak it so that I can run it on all my hundreds of other files without having to amend each file name to remove the seconds?
    – Andy P
    Commented Jul 10, 2016 at 10:22
  • HOORAY! I use the finder batch rename function to replace .00.mov with absolutely nothing. This then allowed the code above to work for all several hundred files in my primary folder. You @patrix are a legend. Thank you.
    – Andy P
    Commented Jul 10, 2016 at 11:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .