在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 多台設備連接,請檢查!!! )