2016-02-04 3 views
0

У меня есть следующий пакетный скрипт, который ищет каталог, в котором он помещен для файла *.apk. Если найдено больше или меньше одного, пользователю будет предложено ввести путь к файлу *.apk.Команда ECHO не выполняется в пакетном скрипте

В конце сценария путь должен быть напечатан. Но каким-то образом выполнение последней части с печатью пути не выполняется. Может ли кто-нибудь дать мне подсказку, почему это происходит?

@echo off 

:: Path to *.apk file 
set PATH_TO_APK= 

:: A temporary file to hold the 
:: path to the *.apk file; because of 
:: Batch variables 
set TMP=tmp.txt 

:: A counter for the number of *.apk files 
:: in the current folder 
set cnt=0 

:: Get the number of *.apks in the current folder 
:: if more than one, than ask the user to enter 
:: path to file; else pick the only *.apk available 

for %%Z in (*.apk) do (
echo %%~fZ>%TMP% 
set /a cnt+=1 
) 

set /P PATH_TO_APK=<%TMP% 
del /F /Q %TMP% 

if %cnt% NEQ 1 (
    echo There is either no *.apk file found or more than one. 

    :: The user is asked to enter the path to the *.apk file 
    set /p PATH_TO_APK="Please enter the path to the *.apk file: " 
    setx PATH_TO_APK "%PATH_TO_APK%" 

    :: If the *.apk does not exist, exit the script 
    if not exist %PATH_TO_APK% (
    echo The path to the application file you entered is not valid. 
    echo Please provide a valid path. 
    echo Exiting script 
) 

echo The path: %PATH_TO_APK% 

ответ

2

Вам не хватает закрывающейся скобки в конце.

 if %cnt% NEQ 1 (

затем

 if not exist %PATH_TO_APK% (

но только одно закрытие) в конце.

Положить другой) перед заключительной строкой.