finally created an account. Learning a lot these past few weeks and have created a batch tool for my fellow techs to use in their travels as we deal with only one software and it's plugins.
I've got this file called sifiledb.ini which has a key and property that needs to be changed fairly often. It's terrible to move to 20 different workstations to do this so I thought I'd wrap it into my batch file.
In this file (sifiledb.ini) we see this.
[FromStation0]
file=\\hostname\PDATA\siomin.sdx
And we need only edit the hostname - the rest of the property needs to stay there. Thing is, it's right in the middle of the ini and it's never in the same spot.
The rest of the file works perfectly and I've tried mixing some pieces in my file from here but I can't put it together.
UPDATE. See below for comment. This is what I have so far. Made a few edits for testing but I get "could not find string"
if "%Oldserver%"=="" echo you need to specify the OLD server's hostname.
set "Oldserver="
set /p "Oldserver=Enter The Value: "
echo.
if "%Newserver%"=="" echo you need to specify the NEW server's hostname.
set "Newserver="
set /p "Newserver=Enter The Value: "
:: file containing string to replace
set file=C:\Sidexis\SIFILEDB.ini
:: string to replace in file (does NOT need to be the whole line)
set searchString=file=\\%Oldserver%\PDATA\siomin.sdx
:: string to write to file (DOES need to be the whole line)
set repString=file=\\%Newserver%\PDATA\siomin.sdx
setLocal enableDelayedExpansion
set count=0
if not exist %file% echo cannot find file - %file% & goto :EOF
:: Search for string - and get it's line number
for /F "delims=:" %%a in ('findstr /N /I /C:"%searchString%" "%file%"') do set searchLine=%%a
if not defined searchLine echo cannot find string - %searchString% - in file - %file% & goto :EOF
:: Read file into variables - by line number
for /F "delims=~!" %%b in ('type %file%') do (
set /a count=!count!+1
set line!count!=%%b
)
:: Edit the one line
set line%searchLine%=%repString%
:: Empty file and write new contents
del %file%
for /L %%c in (1,1,!count!) do echo !line%%c!>>%file%
cls
echo Done
pause
And here is my sifiledb.ini for reference if anyone wants to play with it.
[Location]
Station=JONMER-WIN7X64
DBOwner=
ODBCSrc=PDATA_SQLEXPRESS
ForceReadOnlyOnCreate=1
ForceReadOnlyOnRead=0
ForceReadOnlyOnUpdate=1
[Dialogues]
TimeoutDlg=60
TimeoutMsg=10
QuickSearch=1
DefPatSort=5010
PatListColWidth1=170
PatListColWidth2=75
PatListColWidth3=75
PatListColWidth4=90
PatListColWidth5=100
List=0
TakeGroup=??
[Export]
AddAcceptance=0
TestTimeDelta=90
SetLRLabelXP=1
[TestReports]
documentHeight=842
documentWidth=595
encoding1042=KSCms-UHC-H
encoding1041=90ms-RKSJ-H
encoding1028=ETen-B5-H
encoding2052=GBK-EUC-H
encoding1049=ISO8859-5
encoding1029=CP1250
font1042=Dotum
font1041=MS-Gothic
font1028=SimSun
font2052=MingLiU
[FromStation0]
File=\\JONMER-WIN7X64\PDATA\siomin.sdx
[FromStation1]
File=\\JONMER-WIN7X64\PDATA\siomin1.sdx
[Take]
SetLRLabelXS=1
SetLRLabelXP=1
[Teeth01XP]
00=1
[Teeth02XP]
00=1
[Teeth10XP]
00=1
[Teeth11XP]
00=1
[Teeth12XP]
11=1
12=1
21=1
22=1
31=1
32=1
41=1
42=1
51=1
52=1
61=1
62=1
71=1
72=1
81=1
82=1
[Teeth14XP]
20=1
30=1
[Teeth15XP]
10=1
40=1
FromStation0 is the entry that needs to be changed. FromStation1 can be ignored.
Found the solution! I removed too much and added too little. Here's the perfectly working end result. Thanks guys!
if "%Oldserver%"=="" echo you need to specify the OLD server's hostname.
set "Oldserver="
set /p "Oldserver=Enter The Value: "
echo.
if "%Newserver%"=="" echo you need to specify the NEW server's hostname.
set "Newserver="
set /p "Newserver=Enter The Value: "
:: file containing string to replace
set file=C:\Sidexis\SIFILEDB.ini
:: string to replace in file (does NOT need to be the whole line)
set searchstring=%Oldserver%\PDATA\siomin.sdx
:: string to write to file (DOES need to be the whole line)
set repstring=file=\\%Newserver%\PDATA\siomin.sdx
setLocal enableDelayedExpansion
set count=0
if not exist %file% echo cannot find file - %file% & goto :EOF
:: Search for string - and get it's line number
for /F "delims=:" %%a in ('findstr /N /I /C:"%searchstring%" "%file%"') do set searchLine=%%a
if not defined searchLine echo cannot find string - %searchstring% - in file - %file% & goto :EOF
:: Read file into variables - by line number
for /F "delims=~!" %%b in ('type %file%') do (
set /a count=!count!+1
set line!count!=%%b
)
:: Edit the one line
set line%searchLine%=%repstring%
:: Empty file and write new contents
del %file%
for /L %%c in (1,1,!count!) do echo !line%%c!>>%file%
cls
echo Done
pause