import sys
import os
import subprocess
from xml.dom import minidom
user_input = raw_input("Enter the path of your file: ")
#f = open(user_input,'r+')
#str(f)
apktool = "/usr/share/apktool/apktool.jar"
os.system(apktool + " d " + user_input)
base = os.path.basename(user_input)
a = os.path.splitext(base)[0]
#b = os.path.dirname(user_input)
d = os.path.abspath(os.path.splitext(base)[0])
#print d
#print a
for root,dirs,files in os.walk(os.path.abspath(os.path.splitext(base)[0])):
for filename in files:
if filename.startswith('AndroidManifest'):
pth = os.path.realpath(os.path.join(root,filename))
print pth
Enter the path of your file: /roo/Desktop/test.apk
运行脚本后,“pth”输出提供以下路径:
/root/Desktop/test/AndroidManifest.xml
和/root/Desktop/test/org/AndroidManifest.xml
然而,我对“pth”的期望输出是/root/Desktop/test/AndroidManifest.xml
我如何做到这一点
root
的值在遍历文件夹时会发生变化。在某种程度上,它变成了
/root/Desktop/test/org/
,这就是你得到的/root/Desktop/test/org/AndroidManifest.xml
作为执行pth = os.path.realpath(os.path.join(root,filename))
看起来您想要的路径只是
root
的第一个值,在这种情况下,您可以尝试:pth = os.path.join(os.path.abspath(os.path.splitext(base)[0]), filename)
基本上就是连接你要传递给
os.walk
的路径相关问题 更多 >
编程相关推荐