2017-02-13 41 views
0

我们有一个存储在文件'style.mfx'中的更新许可。我们希望发送给用户,让它静静地以该名称替换旧文件。该文件将始终在c :. 我试过这个演示没有运气。我想在批处理文件中硬编码targetName和replacementFile。我们需要硬编码参数,所以用户需要做的仅仅是运行bat文件来升级许可

@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> 

任何帮助,将不胜感激。

+0

您确定要默默更改用户计算机上的许可证文件吗? – Silverclaw

+0

是的。 '' '' '' ''”。 –

+0

在开发批处理文件时,特别是使用棘手的错误时,删除“@echo off”,然后您可以看到它运行每行代码,并通过缓冲区回滚以找出错误的线索。 – abelenky

回答

1
: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编程例程返回。

相关问题