Monday, 25 February 2019

Android (Oreo) moving files workaround (TAR archive) with preserving time stamp

The issue in Android is that while copying/moving files to other location a new timestamp is created (details can be found here: https://forum.xda-developers.com/android/general/guide-timestamp-attributes-correct-t2960935)

The workaround that works for me is using tar in Terminal or adb while connected to your computer.

example:
I have pictures in internal sdcard (internal memory on my phone) and would like to free up this space moving to external sd card. Regular copy/move creates for them new timestamp (filenames are still the same, so sorting on filenames helps but only if all the files have the same naming convention)

workaround (using adb):
-- to see if your phone is detected
$ adb devices
List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully
ad0617021484e0aaed device

-- connect to your phone's shell and change into DCIM folder with internal photos from camera
$ adb shell
herolte:/ $ cd /sdcard/DCIM/  

-- get location of your external sd card
herolte:/sdcard/DCIM $ ls /storage/                                                                                   
0000-0000  Private  emulated  enc_emulated  self

-- prepare tar archive on external sd card in below location with name zzz_jpg.tar holding all jpg files
$ tar cvf /storage/0000-0000/DCIM/Camera/zzz_jpg.tar *jpg

-- this will delete all jpg files that were put into tar archive (you can do that as last step when you double check that after unpacking tar archive your files are with correct timestamps on exteran sd card -> remember to cd to inernal memory location /sdcard/DCIM/Camera before)
$ rm -rf *jpg

-- unpack on external sd card
$ cd /storage/0000-0000/DCIM/Camera

herolte:/storage/0000-0000/DCIM/Camera $ tar xvf zzz_jpg.tar

-- check timestamps with
$ ls -al