如果存在在 .BAT 文件中不起作用 [英] if exist not functioning in .BAT file

查看:36
本文介绍了如果存在在 .BAT 文件中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 .Bat 文件,如果文件 Startapp.bat 退出,该文件仅运行和复制内容.这个 startapp 文件是在用户在 github 上提交代码时创建的.

I am trying to create a .Bat file that only runs and copy's things if the file Startapp.bat exits. This startapp file is created when a user commits code on github.

我有以下脚本.

taskkill /F /IM Webshop.exe

::%~dp0 means the current folder where this .bat is executed from
SET dest=%~dp0productionEnv

IF EXIST "%~dp0startApp.bat" (
    if not exist "%dest%" mkdir "%dest%" 
    xcopy /Y /s "%~dp0Webshop\bin\Debug" "%dest%"
    SET webDest="%dest%/webContent"

    if not exist %webDest% mkdir %webDest% 
    xcopy /Y /s "%~dp0Webshop\webContent\web" %webDest%
    copy /Y "%~dp0startApp.bat" "%dest%/startApp.bat"
    START "" "%dest%/startApp.bat"
    del "%~dp0startApp.bat"
    echo "Deleted startApp.bat"

) ELSE (
    echo "startApp.bat file not found"
)

但是它不起作用.有时它会同时回显已删除的消息和未找到文件的消息,但这是不可能的.它应该回显这些消息中的任何一个,但不能同时回显两者.这就是为什么有一个 if else.

But it is not working. Sometimes it echos both the deleted message and the file not found message while that shouldn't be possible. It should echo either of those messages but not both. Thats why there is an if else.

请帮忙!

推荐答案

这里是同样的事情,正斜杠固定,如果块改变了不必要的:

Here's the same thing with the forward slashes fixed and the unnecessary if block changed:

Taskkill /F /IM Webshop.exe

If Not Exist "%~dp0startApp.bat" (
    Echo= startApp.bat file not found
    GoTo Next
)

Rem %~dp0 means the current folder where this .bat is executed from
Set "dest=%~dp0productionEnv"
Set "webDest=%dest%\webContent"

If Not Exist "%dest%" MD "%dest%"
XCopy "%~dp0Webshop\bin\Debug" "%dest%" /Y /S
If Not Exist "%webDest%" MD "%webDest%"
XCopy "%~dp0Webshop\webContent\web" "%webDest%" /Y /S
Copy /Y "%~dp0startApp.bat" "%dest%"
Call "%dest%\startApp.bat"
Del "%~dp0startApp.bat"
Echo= Deleted startApp.bat

:Next

这篇关于如果存在在 .BAT 文件中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆