我有一个批处理文件(batch1.bat),它检查UNC共享上的更新版本,然后运行一些命令。但是,问题是我想更新共享上的批处理文件,以便将来的更新在运行批处理时应用于所有用户。问题是批处理文件在检查时没有更新为运行。
示例:
mkdir C:\program\Tools
xcopy /D /Y /e "\\UNC_Share\program\*.*" "C:\program\"
将批处理文件复制到Tools文件夹。
我创建了一个名为update.bat的新文件,它调用上面的xcopy命令,然后打开原始批处理文件(batch1.bat)来完成它的工作。但是,无法弄清楚如何让batch1.bat调用更新,关闭并重新打开批处理而不在循环中调用更新。
UNC上的文件共享
\\UNC_Share\program\
batch1.bat
update.bat
\\UNC_Share\program\Tools
some .exe and .dll files
答案 0 :(得分:0)
这没有问题,因为在不使用命令call
的情况下从批处理文件中运行批处理文件会导致停止处理当前批处理文件并继续处理已启动的批处理文件。
<强> batch1.bat:强>
@echo off
rem Set directory of batch file as current working directory.
cd /D "%~dp0"
rem Check if update was already done before. If the environment variable
rem "UpdateDone" defined in batch file update.bat not set, run the update
rem if the batch file for updating exists at all. Pass as parameter the
rem name of this batch file to restart it after the update.
if "%UpdateDone%"=="" if exist "\\UNC_Share\program\update.bat" "\\UNC_Share\program\update.bat" %0
rem Remove the environment variable "UpdateDone" after update processed.
set UpdateDone=
rem Put here any commands which should be executed by this batch file.
echo Batch1 is processing, please wait ...
<强> update.bat:强>
@echo off
echo Updating tools, please wait ...
rem Target directory automatically created because of switch /I if not exist.
xcopy /D /Y /E /I /Q "\\UNC_Share\program\*" "C:\program\Tools\" 1>nul
rem If there was no argument passed on running this batch file, there
rem is nothing else to do. Otherwise it is expected that the first
rem argument is the name of the batch file which started this batch
rem file for updating the tools and therefore start this batch file
rem now again after setting the environment variable "UpdateDone".
if not "%~1"=="" (
set UpdateDone=yes
%1
)