Changing content of a file
| newkidonthebloc (13) | |||
| Hi Guys, All i want to do is to change the content of a file. For instance, there is a batch file located at C:\Program Files\Test\test.bat The content of bat file is as follows: ------------------------------------------------------------ rem Remove files left over from updating IF EXIST .\updates.bat DEL .\updates.bat IF EXIST .\erupdates.bat DEL .\erupdates.bat IF EXIST .\jre\lib\ext\indicim.jar DEL .\jre\lib\ext\indicim.jar .\jre\lib\security.jar;.\jre\lib\core.jar;.\jre\lib\server.jar;.\jre\lib\graphics.jar;.\jre\lib\jawas.jar;.\jre\lib\jaws.jar;.\jre\lib\xml.jar;.\jre\lib\charsets.jar -mx64M services.ttt.retfg.er.erMain IF errorlevel 99 goto updatesok goto end :updatesok XCOPY .\Updates\erupdates.bat . /E IF EXIST .\erupdates.bat .\erupdates :end --------------------------------------------------------------- I just want to change this file to have following content (That is basically one more command inserted in between): ------------------------------------------------------------ rem Remove files left over from updating IF EXIST .\updates.bat DEL .\updates.bat IF EXIST .\erupdates.bat DEL .\erupdates.bat IF EXIST .\jre\lib\ext\indicim.jar DEL .\jre\lib\ext\indicim.jar .\jre\lib\security.jar;.\jre\lib\core.jar;.\jre\lib\server.jar;.\jre\lib\graphics.jar;.\jre\lib\jawas.jar;.\jre\lib\jaws.jar;.\jre\lib\xml.jar;.\jre\lib\charsets.jar -mx64M services.ttt.retfg.er.erMain .\..\..\"Test Manager"\TMstart.exe IF errorlevel 99 goto updatesok goto end :updatesok XCOPY .\Updates\erupdates.bat . /E IF EXIST .\erupdates.bat .\erupdates :end --------------------------------------------------------------- I am new to comp science so your ideas would be helpful a good deal. Personally i thought that it can be achieved using a batch script but wonder if it can be done using C++ as i want the final tool to be an .exe file which perform the above intended operation when executed. | |||
| Duoas (1596) | |||
| Unfortunately, even with all the updates to cmd.exe, the fellas over at MS never figured people would do stuff like you want in pure batch script, so you'll need to write yourself a little C++ program (or use another shell interpreter) to do it. In C++, a deque of lines is probably the easiest to modify.
How you get the filename and line number to insert the new line(s) is, of course, up to you. You might also want to look at the deque::insert documentation for variations. Hope this helps. | |||
This topic is archived - New replies not allowed.
