0

I am using a tool that generates an .apk file which I wish to automatically install and launch. I created an extremely simple batch script for this, however the filename of the .apk file changes based on the version number, so I am forced to change my .bat file during every version change.

How can I select the most recently modified file in a .bat script?

David Mulder
  • 26,123
  • 9
  • 51
  • 114
  • 1
    Possible duplicate of [How to get the most recent file using a batch script in windows](http://stackoverflow.com/questions/11539726/how-to-get-the-most-recent-file-using-a-batch-script-in-windows) – mwfearnley Apr 07 '17 at 10:21

1 Answers1

2

The following for loop loops through all the files in directory and sets the variable %FILE_TO_INSTALL% each time leaving the last value set as the correct one.

@ECHO OFF
for /f %%i in ('dir /b/a-d/od/t:w') do set FILE_TO_INSTALL=%%i >NUL
echo Installing %FILE_TO_INSTALL%
@ECHO ON

And just in case somebody ends up here though google with the exact same scenario as me, here is the rest:

adb install -r %FILE_TO_INSTALL%
adb shell monkey -p %NAME_OF_YOUR_APP% -c android.intent.category.LAUNCHER 1
David Mulder
  • 26,123
  • 9
  • 51
  • 114