Discussion Locked

Batch file to edit a batch file.

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a batch file that our users use to do a simple xcopy backup to one of our servers. I need to know if and how to write a batch file that would edit the existing one and do a find and replace type of command to change the server name in batch 1to a new server name.

Here is an example of one of the comand lines

( xcopy e:\temp\*.* \\acct\BACKUPS3\user1\Data /s/e/v/h/i)

I want to change it to

(xcopy e:\temp\*.* \\sales\BACKUPS3\user1\Data /s/e/v/h/i).

Any help would be very grateful. I have about 300 machines I need to do this to. I do have some software to push this down to the machines once I have a fix for it. I just need a fix first :)

Thanks in advance.
Bra-k

7 replies

by mloveless

You can replace the batch file vice trying to edit the existing one. That would be much easier. I am not a batch file expert but maybe use the software you have to delet the current batch file then copy the new one. This would take less time and work a little better.

by bra-k

I do not want to replace these batch files. I need to modify them only. Each batch file is custom made to include the users ID name so if I made new batch files the would be to time consuming. I just need to change the name of the server it goes to only. So I need something that will modify the batch not replace it.

by chrissaw

Hi,
The way to resolve it is by using %1 variables.

I create one here doing what you want.

Batch file 1: Named test.bat
if "%1"=="" goto ACCT
xcopy e:\temp\*.* \\%1\BACKUPS3\user1
\Data /s/e/v/h/i
goto end

:ACCT
xcopy e:\temp\*.* \\ACCT\BACKUPS3\user1
\Data /s/e/v/h/i

:end

Batch file 2: Named test2.bat
call test.bat SALES

by bra-k

I do not want to replace these batch files. I need to modify them only. Each batch file is custom made to include the users ID name so if I made new batch files the would be to time consuming. I just need to change the name of the server it goes to only. So I need something that will modify the batch not replace it.

by chrissaw

What I sent you is not a replacement. I think you misread my answer. I show you how to use variables to replace what you want in your batch file.

I use a lot of these batch files and they work all.

by bra-k

I understand what you gave me, but I need a batch that I can run and it will go and modify an existing batch file. What you sent me is the code to put in my existing batch. I have about 300 of these files already on users machines. I need a batch that will open the existing batch find the old server name and change it to the new server name, then save and close the original batch with the new server name in it. Like I mentioned in my question it needs to act simalar to a find and replace statement. Not variables. I do not want to have to open every batch on each computer and do this manually.

Bra-k

I am very willing to give the points to the person that gives me what I am looking for.

This discussion is closed to new replies.