When moving files around tru different dirs and across PC / smartphone, timestamp for last modified date usually get reset to the very datetime of move / copy operation. This lead to files being non-chronologically sorted in some apps (Gallery), quite annoying especially for Images and Videos.
Usually these kind of files follows the naming convention of IMG_YYYYMMDD_HHMMSS.jpg for Images and VID_YYYYMMDD_HHMMSS.mp4 for Videos.
So I thought about combining touch
and extracting character from filenames, the timestamp being in effect part of the filename itself.
I found this script at Ephestione's HQ
for i in IMG*.jpg; do busybox touch -t ${
i:4:8
}
${
i:13:4
}
.${
i:17:2
}
$i; done
but works in terminal only. I tried to make a script out of it but it doesn't work (see below)
#!/system/bin/sh
#change timestamp for images filename IMG_YYYYMMDD_HHMMSS.jpg
for i in IMG_*.jpg
do
touch -t ${
i:4:8
}
${
i:13:4
}
.${
i:17:2
}
$i
done
#change timestamp for whatsapp images IMG-YYYYMMDD-WAnnnn.jpg
for i in IMG-*WA*.jpg
do
touch -t ${
i:4:8
}
1234 $i
done
#change timestamp for videos filename VID_YYYYMMDD_HHMMSS.mp4
for i in VID_*.jpg
do
touch -t ${
i:4:8
}
${
i:13:4
}
.${
i:17:2
}
$i
done
#change timestamp for whatsapp videos IMG-YYYYMMDD-WAnnnn.mp4
for i in VID-*WA*.mp4
do
touch -t ${
i:4:8
}
1234 $i
done
Ideally I'd like to put a script like this in the top level DCIM or Pictures directory and have it process all the Images and Videos in the subdirs. Of course I'm rooted.