【问题标题】:ECHO command does not get executed in Batch scriptECHO 命令未在批处理脚本中执行
【发布时间】:2016-02-04 10:57:12
【问题描述】:

我有以下批处理脚本,它会在放置它的目录中搜索*.apk 文件。如果发现多于或少于一个,则要求用户输入*.apk 文件的路径。

在脚本的末尾应该打印路径。但不知何故,通过打印路径执行最后一部分并没有被执行。有人可以告诉我为什么会这样吗?

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

【问题讨论】:

    标签: windows batch-file echo


    【解决方案1】:

    你在末尾缺少一个右括号。

         if %cnt% NEQ 1 (
    

    然后

         if not exist %PATH_TO_APK% (
    

    但只有一个结尾 )。

    在最后一行之前加上另一个 )。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      相关资源
      最近更新 更多