赞
踩
https://blog.csdn.net/babytiger/article/details/108468363
上回说到如何拉取文件,但是要拉取指定文件夹下,指定大小的所有jpg文件,如果目录不多还好,一个一个拉,但是如果文件夹很多,名字我也不知道,怎么办?写个脚本就可以了
pull_all.bat
- @echo off
- setlocal enabledelayedexpansion
- if %1.==. (
- echo please input device no.
- goto end
- )
-
- for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -name %3 -size +%4 -size -%5`) do (
- set text=%%F
- set mfile=!text!
- adb pull "!mfile!" %6
- )
- :end
- endlocal
runpull_all.bat,实际上就是调用pull_all.bat ,加了参数,顺序为 1机器序列号 2拉取路径 3文件类型 4多少K以上 5多少K以下 本地存放路径,为啥加多少K以下的限制呢,因为我发现有人经常会把1个G左右的带颜色的电影改成jpg后缀的,这要拉下来会很耗时的。所以我们只拉200k 到10M的jpg图片。机器序列号要靠 adb devices来获取。如果只连一个设备可以改进上面的脚本。
- chcp 65001
- echo “机器序列号 拉取路径 文件类型 多少K以上 多少K以下 本地存放路径"
- pull_all.bat nz9dzdpvb6ylx4am /sdcard/ *.jpg 200k 10000k ./localdir
这样,我们就可以 一下拉取所有的jpg文件了。
过了一阵,业务需求又变了,要一下拉取 *.jpg 和 *.png和*.gif 且大小都在200k以上,10M以下,于是脚本又变了,如下
- @echo off
- setlocal enabledelayedexpansion
- if %1.==. (
- echo please input device no.
- goto end
- )
- echo adb -s %1 shell find %2 -size +%4 -size -%5 -name '*.jpg' -o -name '*.png' -size +%4 -size -%5 -o -name '*.gif' -size +%4 -size -%5
- for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -size +%4 -size -%5 -name '*.jpg' -o -name '*.png' -size +%4 -size -%5 -o -name '*.gif' -size +%4 -size -%5`) do (
- set text=%%F
- set mfile=!text!
- adb pull "!mfile!" %6
- )
- :end
- endlocal
有个问题就是 -o的作用域名 貌似加
另外在代码只加::表示注释不能加在do函数中间
- @echo off
- setlocal enabledelayedexpansion
- if %1.==. (
- echo please input device no.
- goto end
- )
- ::echo adb -s %1 shell find %2 -size +%4 -size -%5 -name %3
- ::for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -name %3 -size +%4 -size -%5`) do (
- for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -name %3 -size +%4 -size -%5`) do (
- ::for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -size +%4 -size -%5 -name '*.jpg' -o -name '*.png' -size +%4 -size -%5`) do (
- ::for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -size +%4 -size -%5 -name '*.jpg' -o -name '*.png' -size +%4 -size -%5 -o -name '*.gif' -size +%4 -size -%5`) do (
- set text=%%F
- set mfile=!text!
- adb pull "!mfile!" %6
- )
- :end
- endlocal

上面的代码执行就出问题了提示 do was unexpected at this time.
改成下面的就OK了
- @echo off
- setlocal enabledelayedexpansion
- if %1.==. (
- echo please input device no.
- goto end
- )
- ::echo adb -s %1 shell find %2 -size +%4 -size -%5 -name %3
- ::for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -name %3 -size +%4 -size -%5`) do (
- ::for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -size +%4 -size -%5 -name '*.jpg' -o -name '*.png' -size +%4 -size -%5`) do (
- ::for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -size +%4 -size -%5 -name '*.jpg' -o -name '*.png' -size +%4 -size -%5 -o -name '*.gif' -size +%4 -size -%5`) do (
- for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -name %3 -size +%4 -size -%5`) do (
- set text=%%F
- set mfile=!text!
- adb pull "!mfile!" %6
- )
- :end
- endlocal

赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。