gpt4 book ai didi

batch-file - 如何在批处理文件中使用 if - else 结构?

转载 作者:行者123 更新时间:2023-12-03 04:30:29 28 4
gpt4 key购买 nike

我对批处理文件中的 if - else 结构有疑问。每个命令单独运行,但我无法安全地使用“if - else” block ,因此我的程序的这些部分不起作用。我怎样才能使这些部件运行?谢谢。

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%"
)

最佳答案

您的语法不正确。您不能使用ELSE IF。看来你其实并不需要它。只需使用多个 IF 语句即可:

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%"
)

很棒的批处理文件引用:http://ss64.com/nt/if.html

关于batch-file - 如何在批处理文件中使用 if - else 结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11081735/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com