1

First of all, I have asked the same question at stack overflow, but I am not sure if it's right over there. That's why I decided to post it here, too.

t'm having a hard time trying to copy the creation and modification date of some files to other files.
I have converted some MXF files to MOV, but unfortunately the new MOV-files don't have the same creation date.
Now I had a look around for similar questions and found different answers, but this seems to be the simplest:

    #!/bin/bash
    for f in *.MXF; do
     touch -r "$f" "${f%MXF}mov"
    done


Unfortunately it doesn't work for me – neither with Terminal nor Automator.
I saved the Code with TextEdit. In Terminal I ran chmod+x to make the file executable and put it in the folder where my MXFs and movs are.

But I'm just getting the following error:
touch: *.MXF: No such file or directory
I have also tried mxf instead of MXF.

This is the output of ls- l from the test folder

-rwxrwxrwx  1 username  staff  258458160  5 Jan  2014 570_0301.MXF
-rwxrwxrwx  1 username  staff  241431870  5 Jan  2014 570_0301.mov
-rwxrwxrwx  1 username  staff  974595120  5 Jan  2014 570_0306.MXF
-rwxrwxrwx  1 username  staff  911745994  5 Jan  2014 570_0306.mov
-rwxrwxrwx  1 username  staff  667679280  5 Jan  2014 570_0308.MXF
-rwxrwxrwx  1 username  staff  624468526  5 Jan  2014 570_0308.mov

Because I managed to get the modification date copied it seems that all the files already have the same date, but this doesn't cover the creation date.

Maybe someone could help me out? Will it change the modification and creation date? Because both are important...
Thank you very much in advance and all the best!


EDIT: Got the script working thanks to user3439894.
But it still doesn't update the creation date...
MXF: created 05.01.2014 06:49, modified 05.01.2014 06:50
mov: created 23.06.2016 05:34, modified 05.01.2014 06:50

Is there any way to correct this?

14
  • You have way to much going on in this question and Stack Overflow is probably a better place to be asking. That said I'd modify the question to have only one code block about what you're trying to attempt and then follow [How to create a Minimal, Complete, and Verifiable example}(stackoverflow.com/help/mcve) to include with that code block. Also include in the info the output of ls -l for the target directory. Continued in next comment... Jun 28, 2016 at 11:31
  • Additionally with a handful of $filename.MXF and $filename.mov files where $filename matched each set of .MXF and .mov files, I tested #1 as for f in *.MXF; do touch -r "$f" "${f%MXF}mov"; done and it worked fine! So what problem are you having with it? Note that the .MXF files cannot be .mxf as this is case sensitive. Same goes for .mov, it must be that and not .MOV. (Which is why I said include the output of ls -l for the target directory.) Jun 28, 2016 at 11:31
  • @user3439894 Thank you for your information. ls -l is showing -rwxrwxrwx for all files inside the folder and drwxrwxrwx for the folder. If #1 works fine for you (and apparently lots of other people) what am I doing wrong to get "touch: *.MXF: No such file or directory"?
    – phramenma
    Jun 28, 2016 at 11:51
  • When you run the code from #1 are you in the directory containing the .MXF and .mov files? BTW I didn't ask just if the permissions on all the files were the same! I asked for the output of ls -l for the target directory so I could actually see the names of the files, etc. Additionally this is why I said you have way to much going on in this question and to limit it to one code block and provide Minimal, Complete, and Verifiable example. You can't possibly expect us to help if we don't have all the relevant facts! Jun 28, 2016 at 11:59
  • Thanks again for the quick answer. I inserted all the code I found to give an overview what I tried and find the best solution for what I want to do... I will know edit the whole question, just a second...
    – phramenma
    Jun 28, 2016 at 12:03

2 Answers 2

5

Since this is not working for you I'm going to suggest you do as fd0 suggested and use SetFile. This will be used in conjunction with GetFileInfo, both of which are a part of Command Line Tools for Xcode.

You do not need to install the Xcode.app which is ~3.80 GB, just ~160 MB for Command Line Tools for Xcode.

In Terminal: xcode-select --install

See How to Install Command Line Tools in OS X Mavericks & Yosemite (Without Xcode), which is also for OS X El Capitan.

Here is a bash script to use with SetFile and GetFileInfo:

#!/bin/bash

for f in *; do

    if [[ -f $f ]] && [[ ${f##*.} == MXF ]] && [[ -f ${f%.*}.mov ]]; then

        cDate="$(GetFileInfo -d "$f")"
        mDate="$(GetFileInfo -m "$f")"

        SetFile -d "$cDate" -m "$mDate" "${f%.*}.mov"

    fi

done

enter image description here

5
  • I'm guessing these files do not reside on a HFS+ file system as I said earlier YMMV.
    – fd0
    Jun 28, 2016 at 16:54
  • @fd0, Unfortunately phramenma didn't say where the files reside or what filesystem. for f in *.MXF; do touch -r "$f" "${f%MXF}mov"; done works just fine for me on an HFS+ filesystem. Both stat and GetFileInfo confirms it works for me without the need to use SetFile. Si since it not working it easier for me to offer a SetFile solution as I have a few times in the past with other posts. Jun 28, 2016 at 17:11
  • @user3439894 Thank you so much for your great help. I really appreciate it and the time you spend on my problems. :/ The files are stored on an exFat-HDD. But unfortunately the original code just copied the modification date. Your new script just did the trick! Thank you again!!! P.S. Which application did you use in the screenshot?
    – phramenma
    Jun 28, 2016 at 20:37
  • @phramenma, You're welcome, glad I could help. I used Sublime Text and use it for some of my scripting needs. Jun 28, 2016 at 21:50
  • @@phramenma, I added another test to the beginning of my if statement: if [[ -f "$f" ]] && ..., just for good measure. This way whatever is in the directory only if it's a normal file ending in .MXF and has a corresponding .mov file will GetFileInfo get the creation date-time and modified date-time and apply them to the target file. Jun 28, 2016 at 22:07
-1

If you just need to copy modification date to creation date on same files you can use my modified script:

#!/bin/bash

for f in *; do


    cDate="$(GetFileInfo -d "$f")"
    mDate="$(GetFileInfo -m "$f")"

    SetFile -d "$mDate" "$f"


done

You must log in to answer this question.

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