android: Recursive copy with adb push

2019-01-30 22:34发布

I think adb's push is file-based. I want to be able to push entire folders. Is there an easy way without scripting?

Thanks!

Edit: I need to work with sub-folders.

Edit: Seems that adb pull is recursive but push is not. So I changed the title and description accordingly.

标签: android adb
9条回答
你好瞎i
2楼-- · 2019-01-30 23:30

I'm gonna dig this even more to give a full solution to this (for linux only), because google redirect to this and I had this exact same problem.

With a simple adb push, the problem is that all the subdirectories must exist BEFORE doing the push, which can be very painful to achieve.

Note that an easy solution is to zip the folder, push the zip then unzip on the device. But let's say you don't have unzip on your device (highly unlikely, really).

You want to push a full tree with a lot of subdirectories to your device in an empty directory myDirectory. There are two steps :

First create all the subdirectories, in your source device:

cd <folder-containing-myDirectory>
find myDirectory/ -type d -exec adb shell mkdir <path-to-folder-containing-myDirectory-in-device>/{} \;

This command find all the subdirectories of myDirectory (including ., so if myDirectory already exists, you will have one error message you can safely ignore) and for each of them, create the matching directory on the device.

then push everything

adb push myDirectory/. <path-to-folder>/myDirectory
查看更多
欢心
3楼-- · 2019-01-30 23:37

I realize this question is a little old and I'm about to mention scripting when the question excluded it, but I'm going to answer this anyway. Mostly, because I wish I had found this answer here, before having to work it out myself.

adb push WILL work recursively, if all of the subfolders are present already. They can be empty, it just seems that adb push can not make folders. I found this to be a useful distinction because one could run a series of commands like this:

$ adb shell mkdir /folder
$ adb shell mkdir /folder/sub1
$ adb shell mkdir /folder/sub2
$ adb push folder

So, yes, one could make a small wrapper script to do this automatically. However, I think the more important point is that it just requires the folders to be there. Which means that if this is something that you are going to update multiple times in the same folder. For instance, adding pictures to an existing subfolder structure would work great over and over again with the single adb push command.

查看更多
别忘想泡老子
4楼-- · 2019-01-30 23:41

Try this (worked with subfolders): adb push mySourceFolder/. myDestAndroidFolder.

Empty folders do not copy to android device.

查看更多
登录 后发表回答