当前位置:   article > 正文

adb 拉取指定大小,类型的文件_adb拉取特定后缀文件

adb拉取特定后缀文件

https://blog.csdn.net/babytiger/article/details/108468363

上回说到如何拉取文件,但是要拉取指定文件夹下,指定大小的所有jpg文件,如果目录不多还好,一个一个拉,但是如果文件夹很多,名字我也不知道,怎么办?写个脚本就可以了

pull_all.bat

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. if %1.==. (
  4. echo please input device no.
  5. goto end
  6. )
  7. for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -name %3 -size +%4 -size -%5`) do (
  8. set text=%%F
  9. set mfile=!text!
  10. adb pull "!mfile!" %6
  11. )
  12. :end
  13. endlocal

runpull_all.bat,实际上就是调用pull_all.bat ,加了参数,顺序为 1机器序列号 2拉取路径 3文件类型 4多少K以上 5多少K以下 本地存放路径,为啥加多少K以下的限制呢,因为我发现有人经常会把1个G左右的带颜色的电影改成jpg后缀的,这要拉下来会很耗时的。所以我们只拉200k 到10M的jpg图片。机器序列号要靠 adb devices来获取。如果只连一个设备可以改进上面的脚本。

  1. chcp 65001
  2. echo “机器序列号 拉取路径 文件类型 多少K以上 多少K以下 本地存放路径"
  3. pull_all.bat nz9dzdpvb6ylx4am /sdcard/ *.jpg  200k 10000k ./localdir

这样,我们就可以 一下拉取所有的jpg文件了。

过了一阵,业务需求又变了,要一下拉取 *.jpg 和 *.png和*.gif 且大小都在200k以上,10M以下,于是脚本又变了,如下 

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. if %1.==. (
  4. echo please input device no.
  5. goto end
  6. )
  7. 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
  8. 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 (
  9. set text=%%F
  10. set mfile=!text!
  11. adb pull "!mfile!" %6
  12. )
  13. :end
  14. endlocal

 

有个问题就是 -o的作用域名 貌似加这种不好用了,只能全写了。

另外在代码只加::表示注释不能加在do函数中间

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. if %1.==. (
  4. echo please input device no.
  5. goto end
  6. )
  7. ::echo adb -s %1 shell find %2 -size +%4 -size -%5 -name %3
  8. ::for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -name %3 -size +%4 -size -%5`) do (
  9. for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -name %3 -size +%4 -size -%5`) do (
  10. ::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 (
  11. ::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 (
  12. set text=%%F
  13. set mfile=!text!
  14. adb pull "!mfile!" %6
  15. )
  16. :end
  17. endlocal

上面的代码执行就出问题了提示 do was unexpected at this time.

改成下面的就OK了

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. if %1.==. (
  4. echo please input device no.
  5. goto end
  6. )
  7. ::echo adb -s %1 shell find %2 -size +%4 -size -%5 -name %3
  8. ::for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -name %3 -size +%4 -size -%5`) do (
  9. ::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 (
  10. ::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 (
  11. for /F "tokens=* USEBACKQ" %%F in (`adb -s %1 shell find %2 -name %3 -size +%4 -size -%5`) do (
  12. set text=%%F
  13. set mfile=!text!
  14. adb pull "!mfile!" %6
  15. )
  16. :end
  17. endlocal

 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/blog/article/detail/56321
推荐阅读
相关标签
  

闽ICP备14008679号