adb 拉取指定大小,类型的文件

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

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值