Reputation: 1
I have very long list of commands in my batch, where a lot of strings depend on file name of the file I work with. So I would like to somehow rewrite those parts of code with diferent variation so I could avoid manualy search for these bits and rewrite them one by one in my long batch whenever I would work with diferent file name of alt file. just an example:
Batch-1-(endlesly-long-bat).bat:
IF EXIST "*.webm" (
REN "*.webm" "COOL-PROJECT.webm"
)
FOR %%a in ("COOL-PROJECT.webm") do ffmpeg.exe -i "%%a" -vcodec copy -acodec copy "%%~na.mp4"
IF EXIST "COOL-PROJECT.mp4" (
MD "COOL-PROJECT"
)
REM so on and so on. order, type or commands itselfs are irelevant
Batch-2-(overwriting-bat).bat:
this bat needs to scan content of "Batch-1-(endlesly-long-bat).bat" and look for specific string of characters "COOL-PROJECT" and when it founds all of them, then it will replace those characters with another string of characters "WORST-NIGHTMARE". so based on input mask phrase (COOL-PROJECT) this batch needs to rewrite specific informations in first batch. (I guess trought opening it within notepad? or there is a cmd way?)
Upvotes: 0
Views: 116
Reputation: 56155
if you use the same string over and over again, it's a good idea to work with variables instead of the string itself.
set "filename=COOL-PROJECT"
IF EXIST "*.webm" (
REN "*.webm" "%filename%.webm"
)
FOR %%a in ("%filename%.webm") do ffmpeg.exe -i "%%a" -vcodec copy -acodec copy "%%~na.mp4"
IF EXIST "%filename%.mp4" (
MD "%filename%"
)
REM so on and so on. order, type or commands itselfs are irelevant
This way, you have to edit only one line instead of many strings distributed in the whole file.
As this is a "one-time-Task" only, you can easily use "find and replace" with your Editor.
Als Golez' idea is a very good one. Just replace set "filename=COOL-PROJECT"
with set "filename=%~1"
and start your batchfile with the desired Name as Parameter:
Batch1.bat "COOL-PROJECT"
No need to edit anything ever again.
Upvotes: 2