简体   繁体   English

ECHO命令未在批处理脚本中执行

[英]ECHO command does not get executed in Batch script

I have the following Batch script, which searches the directory in which it is placed for a *.apk file. 我有以下批处理脚本,该脚本在放置*.apk文件的目录中进行搜索。 If more or less than one is found then the user gets asked to enter a path to an *.apk file. 如果找到一个或多个,则要求用户输入*.apk文件的路径。

At the end of the script the path should get printed. 在脚本末尾,应该打印路径。 But somehow by executing the last part with the printing of the path does not get executed. 但是以某种方式通过打印路径执行最后一部分不会得到执行。 Can someone give me a hint why is this happening? 有人可以给我提示为什么会这样吗?

@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%

You are missing a closing parenthesis at the end. 您最后缺少右括号。

     if %cnt% NEQ 1 (

then 然后

     if not exist %PATH_TO_APK% (

but only one closing ) at the end. 但最后只结束一个)。

Put another ) before the final line. 在最后一行之前放置另一个)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM