Change Date and Time of Creation and Modification of file based on filename in MacOS folder

后端 未结 3 1896
感动是毒
感动是毒 2021-01-15 21:50

I have a lot of files in folder with filenames like

20190618_213557.mp4
20190620_231105.mp4
20190623_101654.mp4
..

I need to change creati

3条回答
  •  终归单人心
    2021-01-15 22:19

    I had the same problems trying to set the date from filename, and struggled a lot with the code suggested here.

    Have to be careful to use the same variable letter for the loop and in the brackets! for i in... {x:4:2} should be for i in... {i:4:2} at least on mac and finish with a semicolon before done. This code should work:

    for i in *.mp4; do
       SetFile -d "${i:4:2}/${i:6:2}/${i:0:4} ${i:9:2}:${i:11:2}:${i:13:2}" "$i";
    done
    

提交回复
热议问题