Posted By

mabafu on 02/15/15


Tagged

Bash timestamp android


Versions (?)

Bash Script to Fix Android Pictures and Videos Timestamp


 / Published in: Bash
 

After copying pictures and videos from my tablet to my PC I noticed that the original timestamp was overriden by the current date.

Fortunatelly the timestamp was still preserved in the files name.

Ex: IMG_20150214_202445.jpg or VID_20140116_091015.3gp

The script must be executed in the image's folder and voilá the original timestamp will be restored.

Please make a backup after executing it! I'll not bother myself with licensing... but this piece of... software may be used as you wish, and at your own peril! I don't claim credit neither responsability over it.

  1. #!/bin/bash
  2.  
  3. #Bash Script to Fix Android Pictures and Videos Timestamp
  4.  
  5. ##################################
  6. #Works for files named under this format: AAAAYYYYMMDD_HHMMSS.EXT
  7. #Where:
  8. #A = any character
  9. #YYYYMMDD = year month day
  10. #HHMMSS = hour minute second
  11. #.EXT = any 3 character extension preceeded by a period
  12. #
  13. # It must be executed from the pictures/videos folder
  14. ######################
  15.  
  16. clear
  17. FILES="$( ls )"
  18.  
  19. for file in $FILES
  20. do
  21. YEAR="${file:4:4}"
  22. MONTH="${file:8:2}"
  23. DAY="${file:10:2}"
  24. HOUR="${file:13:2}"
  25. MINUTE="${file:15:2}"
  26. SECOND="${file:17:2}"
  27.  
  28. touch -a -m -t $YEAR$MONTH$DAY$HOUR$MINUTE.$SECOND $file
  29.  
  30. echo $DAY/$MONTH/$YEAR $HOUR:$MINUTE:$SECOND -\> $file
  31. done

Report this snippet  

You need to login to post a comment.