Bash Script to Fix Android Pictures and Videos Timestamp


/ Published in: Bash
Save to your folder(s)

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 before executing it!

I'll not bother myself with licensing. This piece of... software... may be used as you wish, and also at your own peril! I don't claim credit neither responsability over it.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.