Batch file (这次转到是意外错误

Batch file (这次转到是意外错误,batch-file,if-statement,syntax,goto,Batch File,If Statement,Syntax,Goto,我下面的代码抛出错误。请帮助。我是批处理文件脚本的新手。它显示语法错误和“这次转到意外”错误。 我的动机是创建一个批处理文件,该文件将接受用户的参数。基于该参数,它将执行任务。例如,如果输入是sql,它将执行sql脚本。如果输入是foldercreation,它将创建一个新文件夹 @echo off cls set /p FileType=Type of file : if "%FileType%==SQL" (goto sql) if "%FileType%==TXT" (goto text

我下面的代码抛出错误。请帮助。我是批处理文件脚本的新手。它显示语法错误和“这次转到意外”错误。 我的动机是创建一个批处理文件,该文件将接受用户的参数。基于该参数,它将执行任务。例如,如果输入是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 "this is not valid" (goto sql)
if
命令中,您需要一个条件。如果需要比较两个字符串,则应为

if "%FileType%"=="SQL" (goto sql)
   ^..........^  ^...^
if exist _Deploy.txt (
    here the code to execute if the file exist
)
当解析器用变量引用的值替换变量引用时,在
=
运算符的每一侧以一个带引号的字符串结尾

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

还有,线路

if exist _Deploy.txt
缺少命令部分。如果打算执行
If
后面的代码块,则应

if "%FileType%"=="SQL" (goto sql)
   ^..........^  ^...^
if exist _Deploy.txt (
    here the code to execute if the file exist
)

啊。是的。将删除我的答案。谢谢..但在进行更改后,我仍然得到命令语法不正确的错误。我现在该怎么办?@Meen,查看更新的答案。检查所有
条件是否正常。如果仍然有问题,请删除
echo off
,并查看问题出现的位置。我想我已经找到了问题…但仍然不是解决方案…:(代码的问题是批处理没有执行子系统的所有代码…我的意思是,当我尝试在子系统中仅使用1行时,它们工作正常..b但不是多行子系统/p文件类型=文件类型:if%FileType%==SQL goto SQL if%FileType%==TXT goto TEXT if%FileType%==BAT goto BAT if%FileType%==FolderCreation goto FolderCreation If%FileType%==FTP转到FTP:TEXT move/-y“D:\artifacts\Art1\test1.txt”“D:\artifacts\Art2\”>\u Deploy.txt 2>&1退出/b:FTP move/-y“D:\artifacts\Art1\test2.txt”“D:\artifacts\Art2\”>\u Deploy.txt 2>&1退出/b:bat调用testbatchcreatefolder.batch.bat>\u Deploy.txt 2>&1退出/b