我们需要对参数进行硬编码,因此用户需要做的就是运行 bat 文件来升级许可证



我们有一个更新的许可证存储在文件'style.mfx'中。我们希望发送给用户,并让它以该名称静默替换旧文件。文件将始终位于 c: 中。我尝试过这个演示,但没有运气。我想在批处理文件中对目标名称和替换文件进行硬编码。

@echo off
set targetName=%~NX1
set replacementFile=%~F2
call :processFolder
goto :EOF
:processFolder
rem For each folder in this level
for /D %%a in (*) do (
rem Enter into it, process it and go back to original
cd %%a
if exist "%targetName%" (
copy "%replacementFile%" "%targetName%" /Y
)
call :processFolder
cd ..
)
exit /B

cmd 行甚至不起作用! 但是我想要批处理文件中的参数...

app teststyle.mfx c:teststyle.mfx
c:UsersJosephDesktop>replace.bat teststyle.mfx c:teststyle.mfx
c:UsersJosephDesktop>

任何帮助将不胜感激。

:processFolder
rem For each folder in this level
for /D %%a in (*) do (
rem Enter into it, process it and go back to original
 pushd "%%a"
 if exist "%targetName%" (
 copy "%replacementFile%" "%targetName%" /Y
 popd
)
goto :eof

pushd/popd可用于保存和返回。

到达文件末尾将从 call ed 例程返回。

最新更新