如何使用,如果 - else结构在批处理文件? [英] How to use if - else structure in a batch file?
本文介绍了如何使用,如果 - else结构在批处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,如果 - 在一个批处理文件else结构。每个命令单独运行,但我不能用如果 - 其他安全模块,所以我的计划的这些部分不起作用。我怎样才能做到使这些器件上运行?谢谢你。
IF%F%== 1 IF%C%== 1(
::复制文件C到D
复制%的资源文件%%destinationFile%
)
ELSE IF%F%== 1 IF%C%== 0(
::文件移动C到D
将%的资源文件%%destinationFile%
)ELSE IF%F%== 0 IF%C%== 1(
::复制从D一个目录c,/ S:BOS olanlarhariç,/ E:BOS olanlar达希尔
XCOPY%sourceCopyDirectory%%destinationCopyDirectory%/ S / E
)
ELSE IF%F%== 0 IF%C%== 0(
::移动目录
XCOPY / E%sourceMoveDirectory%%destinationMoveDirectory%
RD / S / Q%sourceMoveDirectory%
)
解决方案
您语法不正确。如果您不能使用 ELSE。看来,你真的不需要也无妨。只需使用多个
如果
语句:
IF%F%== 1 IF%C%== 1(
::复制文件C到D
复制%的资源文件%%destinationFile%
)IF%F%== 1 IF%C%== 0(
::文件移动C到D
将%的资源文件%%destinationFile%
)IF%F%== 0 IF%C%== 1(
::复制从D一个目录c,/ S:BOS olanlarhariç,/ E:BOS olanlar达希尔
XCOPY%sourceCopyDirectory%%destinationCopyDirectory%/ S / E
)IF%F%== 0 IF%C%== 0(
::移动目录
XCOPY / E%sourceMoveDirectory%%destinationMoveDirectory%
RD / S / Q%sourceMoveDirectory%
)
大批量文件参考: http://ss64.com/nt/if.html
I have a question about if - else structure in a batch file. Each command runs individually, but I couldn't use "if - else" blocks safely so these parts of my programme doesn't work. How can I do make these parts run? Thank you.
IF %F%==1 IF %C%==1 (
::copying the file c to d
copy "%sourceFile%" "%destinationFile%"
)
ELSE IF %F%==1 IF %C%==0 (
::moving the file c to d
move "%sourceFile%" "%destinationFile%"
)
ELSE IF %F%==0 IF %C%==1 (
::copying a directory c from d, /s: boş olanlar hariç, /e:boş olanlar dahil
xcopy "%sourceCopyDirectory%" "%destinationCopyDirectory%" /s/e
)
ELSE IF %F%==0 IF %C%==0 (
::moving a directory
xcopy /E "%sourceMoveDirectory%" "%destinationMoveDirectory%"
rd /s /q "%sourceMoveDirectory%"
)
解决方案
Your syntax is incorrect. You can't use ELSE IF
. It appears that you don't really need it anyway. Simply use multiple IF
statements:
IF %F%==1 IF %C%==1(
::copying the file c to d
copy "%sourceFile%" "%destinationFile%"
)
IF %F%==1 IF %C%==0(
::moving the file c to d
move "%sourceFile%" "%destinationFile%"
)
IF %F%==0 IF %C%==1(
::copying a directory c from d, /s: boş olanlar hariç, /e:boş olanlar dahil
xcopy "%sourceCopyDirectory%" "%destinationCopyDirectory%" /s/e
)
IF %F%==0 IF %C%==0(
::moving a directory
xcopy /E "%sourceMoveDirectory%" "%destinationMoveDirectory%"
rd /s /q "%sourceMoveDirectory%"
)
Great batch file reference: http://ss64.com/nt/if.html
这篇关于如何使用,如果 - else结构在批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文