[英]ECHO command does not get executed in Batch script
我有以下批處理腳本,該腳本在放置*.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%
您最后缺少右括號。
if %cnt% NEQ 1 (
然后
if not exist %PATH_TO_APK% (
但最后只結束一個)。
在最后一行之前放置另一個)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.