( goto was unexpected this time error

( goto was unexpected this time error

我下面的代码抛出错误。请帮忙。我是批处理文件脚本的新手。它显示语法错误和 "goto was unexpected this time" 错误。 我的动机是创建一个批处理文件,它将接受来自用户的参数。基于该参数,它将执行任务。就像输入 sql 一样,它将执行 sql 脚本。如果输入是 foldercreation,它将创建一个新文件夹。

@echo off
cls

set /p FileType=Type of file :
if "%FileType%==SQL" (goto sql)
if "%FileType%==TXT" (goto text)
if "%FileType%==BAT" (goto bat)
if "%FileType%==FolderCreation" (goto FolderCreation)
if "%FileType%==FTP" (goto ftp)


:sql
set /p SName=Server Name :
set /p DbName=Database Name :
if exist _Deploy.txt del _Deploy.txt
@echo on
sqlcmd -S %SName% -E -d %DbName% -I -i "D:\Script\Execute_Script.sql" >>_Deploy.txt 2>&1
@notepad _Deploy.txt
exit /b

:text
if exist _Deploy.txt
@echo on
move /-y "D:\artifacts\Art1\test1.txt" "D:\artifacts\Art2\">>_Deploy.txt 2>&1
@notepad _Deploy.txt
exit /b

:bat
if exist _Deploy.txt
@echo on
call testbatchcreatefolder.bat>>_Deploy.txt 2>&1
@notepad _Deploy.txt
move /-y "D:\artifacts\Art1\testbatchcreatefolder.bat" "D:\artifacts\Art2\"
exit /b

:FolderCreation
set /p Mypath=Path please :
set /p Myfoldername=folder name :
set folder_path=%Mypath%\%Myfoldername%
md "%folder_path%"
exit /b

:FTP
if exist _Deploy.txt
@echo on
move /-y "D:\artifacts\Art1\test2.txt" "D:\artifacts\Art2\">>_Deploy.txt 2>&1
@notepad _Deploy.txt
exit /b

pause

set /p delExit=Press the ENTER key to exit...:
:end
if "%FileType%==SQL" (goto sql)
   ^...............^ = one string

所以前面的代码等同于

if "this is not valid" (goto sql)

if 命令中你需要一个条件。如果它需要比较两个字符串,它应该是

if "%FileType%"=="SQL" (goto sql)
   ^..........^  ^...^

当解析器用它的值替换变量引用时,您在 == 运算符的每一侧以一个带引号的字符串结尾

应该在所有类似的行中进行此更改。

此外,行

if exist _Deploy.txt

缺少命令部分。如果打算执行 if 之后的代码块,那么它应该是

if exist _Deploy.txt (
    here the code to execute if the file exist
)