我是Shell Scripting的新手。能帮我写下面的要求代码吗?我尝试使用for循环,但它没有用。
我有文件夹" ApkFiles"它有100个.apk文件
我需要在文件夹
中的所有.apk文件上运行以下命令echo nameOfEachApk >> minTarget.xls
aapt.exe d badging eachAPKName.apk | grep -E 'sdkVersion|targetSdkVersion' >> minTarget.xls
我感谢所有的帮助。
答案 0 :(得分:0)
这将迭代python文件夹所在的目录。只需将它放在apkfiles目录中的.py文件中并运行它。我无法测试它,因为我没有确切的设置,但它应该按照你的要求进行测试。
from subprocess import call
import os
# Get current working directory
cwd = os.getcwd()
# Get a list of files in the current working directory
f = open("minTarget.xls")
for apkFile in os.listdir(cwd):
# These call commands will run the shell commands you need
# The [:4] strips off the .apk from the file string
call(["echo", apkFile[:-4], ">>", "minTarget.xls"], stdout=f)
call(["aapt.exe", "d", "badging", apkFile, "|", "grep", "-E", "'sdkVersion|targetSdkVersion'", ">>", "minTarget.xls"], stdout=f)
f.close()
要了解我如何调用shell命令的说明,请查看subprocess module