批量多条件if else == batch ==

时间:2015-10-29 22:26:47

标签: batch-file if-statement conditional-statements move

我想知道如何使用多路复用。比如我正在寻找 如果文件夹(A)存在,则将其移动到另一个文件夹(B) 否则,如果文件夹(B)存在,则将其移动到另一个文件夹(A)否则msg *没有这样的直接

代码:

exp n+1

2 个答案:

答案 0 :(得分:0)

此代码存在多个问题。首先,msg不是批处理命令。请尝试使用echo。接下来,exist语句的路径必须位于括号之前。最后还有一个不必要的括号,最后,代码末尾的pause仅在else语句为真时才有效,因为exit退出脚本本身,不是嵌套语句。固定代码如下:

if exist C:\Users\%username%\AppData\ABC\ (
taskkill /f /im File.exe 
move C:\Users\%username%\ABC C:\Windows\system\ABC2\
echo * Move 
) else if exist C:\Windows\system\Cool\ (
taskkill /f /im Viber.exe
move C:\Windows\system\Cool C:\Users\%username%\AppData\Roaming\ViberPC\
echo * You will active your viber thank you Enjoy it baby. i love you all 
) else ( 
echo * This account (number) does not exist please singup on your smartphone to get acces thank you ... have a nice day
)
pause

还有一些拼写错误。我离开他们以防他们故意。

答案 1 :(得分:0)

以下示例显示了IF syntax

@echo off
if exist ABC (
  echo "ABC" exist
) else if exist Cool (
  echo "ABC" doesn't exist but "Cool" exist  
) else (
  echo "ABC" nor "Cool" exists.
)
pause

最后一件事,在echo命令中,您必须escape括号。

@echo off
if exist C:\Users\%username%\AppData\ABC\nul (
  taskkill /f /im File.exe 
  move C:\Users\%username%\ABC C:\Windows\system\ABC2\
  echo Move done
) else if exist C:\Windows\system\Cool\nul (
  taskkill /f /im Viber.exe
  move C:\Windows\system\Cool C:\Users\%username%\AppData\Roaming\ViberPC\
  echo You will active your viber thank you Enjoy it baby. i love you all 
) else ( 
  echo This account ^(number^) does not exist,
  echo please sign up on your smart phone to get access
  echo Thank you. Have a nice day.
)
pause