Reputation: 70
I would like to update a line in a few different batch files at the same time.
How would I go about writing something to change multiple identical lines in a file.
Specifically, every week I have a BAT file create a new folder labeled "Week monthdayyear"
I have other BATs that have been made to move files to that new folder throughout the week. Currently the only thing I know how to do is manually change the date in each of the BATs that move files to that folder every week. I would like to have my BAT file that creates the new directory to modify the other BATs and input the new directory.
Example:
Each Bat Contains:
ren "...\Week 4-13-2015\..."
I need to change each bat to say
ren "...\Week 4-20-2015\..."
This question is related to another question I asked a week ago. I solved the other question if you want to use it as reference for more background information and the actual scripts. Can a Batch File Tell a program to save a file as? (If so how)
Upvotes: 1
Views: 74
Reputation: 67216
You have a problem of inter-program communication, that is, the program that create the new folder every week needs to inform to the rest of programs the name of the current folder. You may do that via an auxiliary data file. For example, include this (or similar) line in the program that create the folder:
echo Week %monthdayyear%> CurrentWeek.txt
... and get the right name in each one of the rest of programs:
rem Get the name of the current folder
set /P currentFolder=< CurrentWeek.txt
. . .
ren "...\%currentFolder%\..."
Upvotes: 1