简体   繁体   English

执行批处理文件时出错

[英]Error while executing batch file

This is my first time creating a batch file. 这是我第一次创建批处理文件。 I am trying to execute by adding all the following inside a batch file. 我试图通过在批处理文件中添加以下所有内容来执行。 however the flow stops at the for loop. 但是流程在for循环处停止。 these command works when directly executed on command prompt. 这些命令在命令提示符下直接执行时有效。 And I am also facing error with the copy command 而且复制命令也面临错误

SET ROOT="C:\Rahul\Projects\sub-folder"

SET WEB1=%ROOT%\folder1\1.war
SET WEB2=%ROOT%\folder2\2.war

SET SOURCE=%WEB1% %WEB2% 

SET TARGET=C:\Rahul\softwares\apache-tomcat-6.0.29\webapps\

c:
cd C:\Rahul\softwares\apache-tomcat-6.0.29
rmdir /q /s work\Catalina
cd webapps

FOR %i in ("*.war") do rmdir /q /s  %~ni
FOR %i in ("*.war") do del /q /s  %i
FOR %i in (%SOURCE%) do copy %i %TARGET%

FOR %i in ("*.war") do rmdir /q /s %~ni will work in the command line but not in a batch. FOR %i in ("*.war") do rmdir /q /s %~ni将在命令行中运行,但不能批量运行。 Inside a batch file you must replace %i with %%i . 在批处理文件中,必须将%i替换为%%i This should be it. 应该是这样。

In my experience, it is more often easier to not use quoting in the SET statement. 以我的经验,在SET语句中不使用引号通常会更容易。 Then, use quoting whenever it is used. 然后,在使用时使用引号。

SET THEVAR=C:\Program Files
DIR "%THEVAR%\Common Files"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM