我在Windows批处理中使用以下行
SET MOBILE_PATH=/mnt/sdcard/koinoxrista
SET FILE_BILL="adb shell ls %MOBILE_PATH% ^| find /c "Bill.txt" "
这一行adb shell ls %MOBILE_PATH% | find /c "Bill.txt"
给了我1
我想编写一个If语句,如果FILE_BILL等于1则执行某些操作,如果等于0则执行其他操作。如何执行此操作?
if %FILE_BILL% == 1 (
echo the file exists
) else (
echo the file does not exist
)
我总是收到消息file does not exist
答案 0 :(得分:0)
您的问题表明,Bill.txt在指定位置存在(或不存在)非常重要,而find /c "Bill.txt"
不会1
提供%ERRORLEVEL%
。如果是这样,那么当“Bill.txt”出现在adb命令的输出中时,您只需使用{{1}}:
SET MOBILE_PATH=/mnt/sdcard/koinoxrista adb shell ls %MOBILE_PATH% | find /c "Bill.txt" >NUL if %ERRORLEVEL% == 0 ( echo the file exists ) else ( echo the file does not exist )
您可以将%ERRORLEVEL%保存到其他变量以供日后使用。