Search code examples
windowsbatch-filehardcode

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


We have an updated license stored in the file 'style.mfx'. We want to send to user and have it silently replace the old file by that name. The File will always be in c:. I've tried this demo with no luck. I want to hard code targetName and replacementFile in the batch file.

@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 line isn't even working! but I want the arguments in the batch file...

app teststyle.mfx c:\teststyle.mfx

c:\Users\Joseph\Desktop>replace.bat teststyle.mfx c:\teststyle.mfx

c:\Users\Joseph\Desktop>

Any help would be appreciated.


Solution

  • :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 can be used to save-and-return.

    reaching end-of-file will return from a called routine.