I am using the following command to copy the most recently added file from a connected device into the directory that I want:
adb pull sdcard/Robotium-Screenshots/filename.jpg D:\jenkins\jobs\
But it can copy only the file that I specify.
How can I copy the newest file from sdcard/Robotium-Screenshots/
to D:\jenkins\jobs\
without specifying it by name?
Here is a one-liner which would pull the last modified file from a specified folder:
Known limitations:
It relies on
ls
command to do the sorting based on modification time. Historically Android devices had multiple sources for thecoreutils
, namelytoolbox
andtoybox
multi-binaries. Thetoolbox
version did not support timestamp based sorting. That basically means that this won't work on anything older than Android 6.0.It uses
adb exec-out
command to make sure that binary output does not get mangled by thetty
. Make sure to update yourplatform-tools
to the latest version.