A windows batch to read Android TV pkg with install time

@echo off
setlocal enabledelayedexpansion

REM Create a temporary file
echo %cd% 
set tempfile=.\adb_packages.txt
set tempOutput=.\output.txt

REM Get the list of packages
adb shell pm list packages -f > %tempfile%

REM Process each package
for /f "tokens=*" %%a in (%tempfile%) do (
    REM Extract the package name
    set pkg=%%a
    for /f "tokens=2 delims==" %%b in ("!pkg!") do (
        set pkg=%%b
		echo !pkg!
		REM echo %%b
		REM echo %cd% 
		adb shell dumpsys package  %%b > %tempOutput%

		:: Process each line in the file
		for /f "delims=" %%a in (%tempOutput%) do (
			:: Check if the line contains str1 or str2
			echo "%%a" | findstr /C:"firstInstallTime" 1>nul
			if !errorlevel! equ 0 (
				echo !pkg! "%%a"
			)
			echo "%%a" | findstr /C:"lastUpdateTime" 1>nul
			if !errorlevel! equ 0 (
				echo !pkg! "%%a"
			)
		)
 
		del %tempOutput%
    )
)

REM Delete the temporary file
del %tempfile%

endlocal


 

你可能感兴趣的:(windows,batch,android)