Skip to content

Instantly share code, notes, and snippets.

@elleryq
Created January 7, 2014 07:13
Show Gist options
  • Save elleryq/8295733 to your computer and use it in GitHub Desktop.
Save elleryq/8295733 to your computer and use it in GitHub Desktop.
Android 在 1.5/1.6 時,adb push 一次只能傳一個檔案,而且也沒辦法在目錄不存在時自動建立,所以寫了 script 來做這件事情。
import sys
import glob
import os
ANDROID_SDK = "your_android_sdk_path"
ADB=os.path.join(ANDROID_SDK, "tools", "adb")
def upload( target, file ):
from subprocess import call
result = True
p, f = os.path.split( file )
path = os.path.join( (target, p) )
unixfile = "/".join( ( target, p, f) )
try:
print "Making directory %s" % path
call( [ ADB, "shell", "mkdir", path ])
except:
print "Making fail."
result = False
try:
print "Uploading %s" % file
call( [ ADB, "push", file, unixfile ])
except:
print "Upload fail."
result = False
return result
def main():
if len( sys.argv )==1:
print "Need at least 1 parameters."
print "For example: %s target *.jpg *.png" % sys.argv[0]
sys.exit(-1)
target = sys.argv[1]
for filetype in sys.argv[2:]:
for infile in glob.glob( filetype ):
upload( target, infile )
#print( infile )
print "upload ok."
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment