Solved Batch file needed for copy/paste

June 8, 2011 at 21:02:03
Specs: Windows 7
I hope you experts can help me. I have a .ini file that needs a few lines to be copied then paste in the same .ini file but at a diferent location within the same .ini file. Here is an example of what inside the .ini. Basically I need to copy the numbers from "working values" and copy them on top of the "location" numbers. We do this manually every day as the "location" numbers change automatically and need to be as close to "working values" as possible to work. I thought a simple batch file could do this but my knowledge is limited. Thank you and any help would be appreciated.

'offset values
'working values

See More: Batch file needed for copy/paste

Report •

June 16, 2011 at 20:00:11
Anyone have an idea how this can be done?

Report •

June 16, 2011 at 21:43:43
✔ Best Answer
How about this:


FOR /F %%A IN (some.ini) DO (
    ECHO %%A |FINDSTR /V "^vCTI_XDIM ^vCTI_YDIM" >>tmp
        IF /I !ERRORLEVEL! EQU 0 (
            ECHO vCTI_XDIM=-8585>>tmp
        ) ELSE (
            ECHO vCTI_YDIM=-8576>>tmp
MOVE "tmp" "some.ini" 

A rundown of what's happening:
First, the batch environment is setup to run quietly, and to allow variables within a loop to be usable. An empty temp file is created, which will contain a new ini file reflecting the desired values. A loop is started, reading line by line the contents of the current ini file. Each line is then assessed using the FINDSTR command. Any line that doesn't begin with vCTI_XDIM or vCTI_YDIM gets written to the temp file. If a line does begin with either vCTI_XDIM or vCTI_YDIM, the line is explicitly tested (again, with the FINDSTR command) to see if vCTI_XDIM is found. If it is, the desired value for it is written to the temp file. If the line doesn't contain vCTI_XDIM, it must therefore contain vCTI_YDIM, and it's desired value is written to the temp file. Once all the lines have been assessed, the MOVE command overwrites the old ini file with the temp file that contains all of the desired values. The batch file is done, and EXITs.

You should be able to copy and paste all of the fixed-font text into Notepad (replacing all occurrences of "some.ini" with the name of your own .ini file), and save it as "UpdateINI.bat" in the same folder as your .ini file you want updated.

When your only tool is a hammer, every problem looks like a nail.

Report •

June 22, 2011 at 20:22:13
Orangeboy...Thank you very much for your help. Sorry for the late response. I've been off for a few days.
I tried your batch file and it copied what I needed which is perfect! The only thing is some lines with headers such as my example above 'working values it only copied working and not values and some spaces in between some lines were removed or not copied. I know it won't affect the ini file but I like to keep the format original since this is a manufacturing environment.
On another note the ini files are on a network drive and I would like to have the batch file in my local drive so only a few could have access to the batch file incase something goes wrong. This might be much to ask but the ini folder contains 6 ini files. Is it possible to have one batch file to change all 6 ini files? Thanks again for your expertise.

Report •

Related Solutions

June 23, 2011 at 01:21:16
I noticed all the ini files have the same lines 13 and 14 with the numbers that need to be changed daily. Is it possible to have the numbers I need stored somewhere in a file and then have them copy in lines 13 and 14 in the ini files? Maybe this would be easier to do?

Report •

Ask Question