本文介绍了根据MacOS文件夹中的文件名更改创建和修改文件的日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件夹中有很多文件,文件名都像

I have a lot of files in folder with filenames like

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

我需要根据文件名更改创建日期和时间20190618_213557 = YYYYMMDD_HHMMSS在终端中使用bash脚本

I need to change creation date and time based on filename20190618_213557=YYYYMMDD_HHMMSSusing bash script in terminal

推荐答案

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

这篇关于根据MacOS文件夹中的文件名更改创建和修改文件的日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:44
查看更多