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

后端 未结 3 1922
感动是毒
感动是毒 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:03

    MACOS Uses touch -mt to change file creation/modification time. Here is the script:
    
        #!/bin/bash
        FILES="/Users/shakirzareen/Desktop/untitledfolder/*"
        for f in $FILES         ## f = full path + filename
        do
            t="${f##*/}"            ##remove folder path from filename
            t2="${t//_}"            ##remove _ from filename
            t3="${t2%%.*}"          ##remove file extension part
            touch -mt "$t3" $f  ##set creation and modification time of file
        done
    

提交回复
热议问题