在android设备中要创建多个或者多级文件夹时,手动去创建费时费力(有点傻),一个bat文件就能很好的实现这个功能。
1.首先创建同级多个文件夹且在该文件夹下生成一个文件
1 @echo off 2 echo please wait the devices to connect ..... 3 adb wait-for-device 4 echo device connected 5 set /p i=Please input the number of folder you need: 6 :start 7 set /a a+=1 8 echo Start %a% 9 adb shell mkdir /sdcard/%a% 10 adb shell dd if=/dev/zero of=/sdcard/%a%/%a%.img bs=2048k count=2 11 if %a% equ %i% echo OK &goto continue 12 goto start 13 :continue 14 set /p b=Do you want to continue filling ?(Y/N): 15 if /i %b% equ Y echo To fill again,Please press Enter key to start;press Ctrl+C to stop. && pause >nul &goto start && %a%=%i% 16 if /i %b% equ N goto finally 17 goto continue 18 :finally 19 echo ok! 20 pause
附上删除代码:(存在缺陷,若文件夹不存在,还是会显示已删除,没找到可行的方法先去做个判断.........(有个思路,但是好像没法实现),还望大神们指条明路!!!
思路:adb shell find /sdcard/%a% 出现两种结果(存在该文件夹;未找到该文件夹),想着用 %errorlevel%==0去判断,但是find这命令无论找没找到文件夹,都是成功执行的)
1 @echo off 2 set /p i=Please input the number of folder you need : 3 :start 4 set /a a+=1 5 adb shell rm -r /sdcard/%a% 6 echo Deleted %a% 7 if %a% equ %i% echo OK &goto end 8 goto start 9 :end 10 pause
新增删除代码:今天想到了用findstr可以解决(但是有出现新的问题,:( )
1 @echo off 2 set /p a=please enter the number you want to delete: 3 :start 4 set /a var+=1 5 adb shell rm -r /sdcard/%var% |findstr "No such file or directory" 1>nul 2>nul && ( echo %var% not exist) || ( echo %var% deleted ) 6 if %var% equ %a% echo OK! & goto end 7 goto start 8 :end 9 pause 10 11 rem 用for的时候,当不存在该文件夹时,显示的是deleted (注意 & && | || 的用法) 12 rem for /l %%i in (1,1,%a%) do ( 13 rem adb shell rm -r /sdcard/%%i |findstr ”No such file or directory“ 1>nul 2>nul && ( echo not exist ) || ( echo %%i deleted ) 14 rem )
2.创建多级文件夹且在该文件夹下生成一个文件
1 @echo off 2 color 0b 3 rem 不区分大小查找以device结尾的行 4 adb devices | findstr /i "device$" 1>nul 2>nul 5 if not %errorlevel%==0 ( 6 echo Devices not connected ! 7 echo Please check whether the USB is turned on. 8 ) 9 set /p j=Please enter the number recursive diretories: 10 setlocal enabledelayedexpansion 11 set pathdir=sdcard 12 for /l %%i in (0,1,%j%) do ( 13 adb shell mkdir !pathdir!/%%i 14 adb shell dd if=/dev/zero of=!pathdir!/%%i/%%i.img bs=1000k count=1 15 set pathdir=!pathdir!/%%i 16 ) 17 pause
有些地方使用了不同的代码来实现类似的效果。
最后:由于小弟水平有限,代码实现的功能较简单(够用就行);若有不当之处还望指出,如果你有更好的实现方法,希望留言共同探讨。谢谢!
附上判断Android设备连接数量
for /f %%i in ('adb devices ^|find /c "device"') do ( if %%i LEQ 1 echo 没有设备连接,请检查!!! if %%i GEQ 3 echo 多台设备连接,请检查!!! )