简体   繁体   中英

Select last modified file in a Windows batch file

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM