Title: Fixing WhatsApp image dates after Android Migration
Author: Alex Kirk
Published: January 6, 2018

---

# Fixing WhatsApp image dates after Android Migration

January 6, 2018

Recently I've had the issue to have a completely unsorted Photo Library in Android
after migrating to a new phone. The reason is that WhatsApp images are copied into
internal storage and end up with the last modification date when they were copied,
thus conglomerating together when they should be spread out over time.

The problem is not that trivially to solve because you cannot mount internal storage
into a computer and then modify the file dates. Thankfully, I was still able to 
create a viable solution using a bash script.

It all revolves around the Android Terminal Emulator [Termux](https://termux.com)
which allows you to execute scripts on your phone.

 1. Install [ Termux ](https://play.google.com/store/apps/details?id=com.termux).
 2. [Grant Termux access to your storage directories](https://termux.com/storage.html).
 3. Install core tools apt install coreutils
 4. Copy this script into your file tree (for example via [Android File Transfer](https://www.android.com/filetransfer/)):

    ```wp-block-code
    for f in IMG-20* VID-20* AUD-20*; do
        [ -e "$f" ] || continue
        NEWDATE=`echo $f | cut -c5-8`-`echo $f | cut -c9-10`-`echo $f | cut -c10-11`
        echo touch -d $NEWDATE "$f"
        touch -d $NEWDATE "$f"
    done
    ```

 5. Run the script in the directories you need to fix file dates (for example in /storage/
    emulated/0/WhatsApp/Media/WhatsApp Images)
 6. Delete the data of MediaStorage (and maybe reboot) to make Android re-index the
    files with the new file dates.

[Web](https://alex.kirk.at/category/web/)

Read this next

[Fixing WhatsApp image dates after…](https://alex.kirk.at/2018/01/06/fixing-whatsapp-image-dates-after/)

### Leave a Reply 󠀁[Cancel reply](https://alex.kirk.at/2018/01/06/fixing-whatsapp-image-dates-after-android-migration/?output_format=md#respond)󠁿

Only people in [my network](https://alex.kirk.at/friends/) can comment.

This site uses Akismet to reduce spam. [Learn how your comment data is processed.](https://akismet.com/privacy/)