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

We need to hardcode arguments so all the user need to do is just needs to run the bat file to upgrade the license

我们在文件 'style.mfx' 中存储了更新的许可证。我们想发送给用户并让它默默地用那个名字替换旧文件。该文件将始终位于 c: 中。 我试过这个演示但没有运气。我想在批处理文件中硬编码 targetName 和 replacementFile。

@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:\Users\Joseph\Desktop>replace.bat teststyle.mfx c:\teststyle.mfx

c:\Users\Joseph\Desktop>

如有任何帮助,我们将不胜感激。

: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 可用于 save-and-return.

达到 end-of-file 将 return 通过 called 例程。