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