|
Answer» This is for work and the code is taken from this site I just tried tweaking and I'm not getting very far.
Code: [Select]@echo on setlocal enabledelayedexpansion
set log=C:\Vision\batlog set ivdir=C:\Vision set ivlogin=c:\Vision\etc\ivlogin.cfg
set workfolder=C:\Vision\batwork\ md %workfolder%
cd /d %workfolder%
Rem Change ##### to the new SortPatternID Set newID=#####
set holder1=ivlogin1.cfg set holder2=ivlogin2.cfg
set outputfile=IDChg.cfg
MD %log%
Echo-------------------Create log %Date% ^& %time%--------------------->%log%\PattIDChg.log Echo Created to automate Sort Pattern ID changes>>%log%\PattIDChg.log
Echo ----------Save for backup---------->>%log%\PattIDChg.log type %ivlogin%>>%log%\PattIDChg.log Echo ----------------------------------->>%log%\PattIDChg.log
Rem - Pull out anything that is not using the BAT directory, saving to add back to %ivlogin% Rem ^*Reminder, have to figure how to remove -----------and directory name from this file
rem Find /I "0;bat\" %ivlogin%>>%holder1% Find /I /V "0;bat\" %ivlogin%>>%holder2%
for /f "delims=" %%L in (%ivlogin%) do ( set cline=%%L if "!cline:~0,1!"=="0;bat\" ( set /a lc=1 set hline=!cline! set nuline= set /a lc=!lc!+1 ) if !lc! GTR 0 ( if !lc! LSS 3 ( set nuline=!nuline!!cline! ) ) set /a lc=!lc!+1 if !lc! GTR 3 echo !hline!!nuline! >> %holder1% )
if exist %outputfile% del %outputfile%
echo for /f "tokens=1-5 delims=;" %%A in (%holder1%) do (
for /f "tokens=1,2,3,4,5 delims=;" %%A in (%holder1%) do ( echo %%A;%%B;%%C;%%D;%newid%>>%outputfile%
) pause
The IVLOGIN File Code: [Select]0;bat\Sortmvx.bat;MVX - Vision X;; 0;bat\sortsndp.bat;Branch Capture; ;84111 0;bat\sortsndp.bat;Branch Capture; ;82111 0;bat\sortsndp.bat;Branch Capture; ;86111 0;bat\sortsndp.bat;Branch Capture; ;88112 0;etc\xfer.cfg;File Transmissions;; 0;etc\reports.cfg;Reports;; 0;etc\config.cfg;Configuration;; 0;command\prntstmt.bat;Print Image Statements;; 0;command\dream.bat;DREAM Demo;; 0;bin\sps.exe;Sort Pattern Studio;; 0;command\fedecl.bat;Reconcile ECL File;;
0;etc\sorters.cfg;*DR Mode*;; Problem with above file, they are not all going to look like this, it might be something more simple like this ... Code: [Select]0;bat\sortsndp.bat;Branch Capture; ;86888 0;etc\reports.cfg;Reports;; Then I have another problem, inside the same IVLOGIN.cfg file I might have ##### = 88888 on one line and that might need to change to 11111, then on another line I might have ##### = 86888 and that needs to CHANGED to 11112 or something like that, I was thinking I might be able to use the Find command to pull out line with this number then do a change and put it back, or maybe I could do something with tokens to check part of the number and then change it, guess I'm really just in need of some advice, if I can get help with the top part of the code, the Intial change I can probably use IFs and Errorlevels for the rest. Thanks for your help. Modified the code a little, but still confused on how to make it work right.
IVLOGIN2.cfg is a holder file for everything that doesn't start with "0;\bat"
IVLOGIN1.cfg contains this after running ... Code: [Select]0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111 0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111 0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111 0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111 0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111 0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111 0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111 0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111 0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111 0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111 IDchg.cfg - almost seems like it working, but what I don't get is it is using the same line of code over and over again from the original IVLOGIN.cfg file. Not sure what i'm doing wrong in the for loop to cause this.
Code: [Select]0;bat\sortsndp.bat;Branch Capture11; ;##### 0;bat\sortsndp.bat;Branch Capture11; ;##### 0;bat\sortsndp.bat;Branch Capture11; ;##### 0;bat\sortsndp.bat;Branch Capture11; ;##### 0;bat\sortsndp.bat;Branch Capture11; ;##### 0;bat\sortsndp.bat;Branch Capture11; ;##### 0;bat\sortsndp.bat;Branch Capture11; ;##### 0;bat\sortsndp.bat;Branch Capture11; ;##### 0;bat\sortsndp.bat;Branch Capture11; ;##### 0;bat\sortsndp.bat;Branch Capture11; ;##### Made this change to the original IVLOGIN.cfg to help troubleshoot myself ... Code: [Select]0;bat\sortmvx.bat;MVX - Vision X;; 0;bat\sortsndp.bat;Branch Capture11; ;84111 0;bat\sortsndp.bat;Branch Capture223; ;82111 0;bat\sortsndp.bat;Branch Capture343; ;86111 0;bat\sortsndp.bat;Branch Capture4343; ;88112 0;etc\xfer.cfg;File Transmissions;; 0;etc\reports.cfg;Reports;; 0;etc\config.cfg;Configuration;; 0;command\prntstmt.bat;Print Image Statements;; 0;command\dream.bat;DREAM Demo;; 0;bin\sps.exe;Sort Pattern Studio;; 0;command\fedecl.bat;Reconcile ECL File;;
0;etc\sorters.cfg;*DR Mode*;; Code: [Select]@echo on rem setlocal enabledelayedexpansion
set log=C:\Vision\batlog set ivdir=C:\Vision set ivlogin=c:\Vision\etc\ivlogin.cfg
set workfolder=C:\Vision\batwork\ md %workfolder%
cd /d %workfolder%
Rem Change ##### to the new SortPatternID Set newID=#####
set holder1=ivlogin1.cfg set holder2=ivlogin2.cfg
set outputfile=IDChg.cfg
MD %log%
Echo-------------------Create log %Date% ^& %time%--------------------->%log%\PattIDChg.log Echo Created to automate Sort Pattern ID changes>>%log%\PattIDChg.log
Echo ----------Save for backup---------->>%log%\PattIDChg.log type %ivlogin%>>%log%\PattIDChg.log Echo ----------------------------------->>%log%\PattIDChg.log
if exist %outputfile% del %outputfile%
for /f "tokens=1,2,3,4,5 delims=;" %%A in (%ivlogin%) do ( set var=%%E Echo A:%%A , B:%%B , C:%%C , D:%%D , E:%%E - Var:%var% ^& ERRORLEVEL:%Errorlevel%>>%log%\PattIDChg.log If "%%E"=="" ( Rem If / I %var% GTR 0 ( echo %%A;%%B;%%C;%%D;>>%outputfile% ) ELSE ( echo %%A;%%B;%%C;%%D;%newid%>>%outputfile% )
) pause Made some major changes which woot!!! seem to work. So anyone have another idea of getting this to work differently or how to configure if I have newid1 & newid2? Sorry to bump again, just really happy I got this far. Sorry if I piss anyone off by posting again, but I think I got a bit further ... Though now I'm having an issue with the last part of my code Code: [Select]ELSE ( echo %%A;%%B;%%C;%%D;%%E>>%outputfile% I want this bit of code to basically say if none of the other IF statements MATCH then keep the line and Echo it according.
Here is my final modification for now as I've been trying to get it to work the way I want it to for the last 2 hours or so. I still have Error Checking to do and a bit more code, but getting this part done and making it work is the only way I'm going to get anywhere. Thanks for the help.
Code: [Select]@echo on rem setlocal enabledelayedexpansion
set log=C:\Vision\batlog set ivdir=C:\Vision set ivlogin=c:\Vision\etc\ivlogin.cfg
set workfolder=C:\Vision\batwork\ md %workfolder%
cd /d %workfolder%
Rem Change ##### to the Curr/New SortPatternID Set CurrIDP=88888 Set newIDP=11111 Set CurrIDD=77777 Set newIDD=22222 Set CurrIDO=66666 Set newIDO=33333
set outputfile=IDChg.cfg
MD %log%
Echo -------------------Create log %Date% ^& %time%--------------------->%log%\PattIDChg.log Echo Created to automate Sort Pattern ID changes>>%log%\PattIDChg.log
Echo ----------Save for backup---------->>%log%\PattIDChg.log type %ivlogin%>>%log%\PattIDChg.log Echo ----------------------------------->>%log%\PattIDChg.log
if exist %outputfile% del %outputfile%
Echo.>>%log%\PattIDChg.log Echo Below ^Echo statements might help with troubleshooting ... >>%log%\PattIDChg.log for /f "tokens=1,2,3,4,5 delims=;" %%A in (%ivlogin%) do ( Echo A:%%A , B:%%B , C:%%C , D:%%D , E:%%E ^& errorlevel:%Errorlevel%>>%log%\PattIDChg.log If "%%E"=="" ( echo %%A;%%B;%%C;%%D;>>%outputfile% ) ELSE ( If "%%E"=="%CurrIDP%" echo %%A;%%B;%%C;%%D;%newIDP%>>%outputfile% If "%%E"=="%CurrIDD%" echo %%A;%%B;%%C;%%D;%newIDD%>>%outputfile% If "%%E"=="%CurrIDO%" echo %%A;%%B;%%C;%%D;%newIDO%>>%outputfile% ) ELSE ( echo %%A;%%B;%%C;%%D;%%E>>%outputfile% ) pauseCode: [Select] If "%%E"=="" ( echo %%A;%%B;%%C;%%D;>>%outputfile% ) ELSE ( If "%%E"=="%CurrIDP%" echo %%A;%%B;%%C;%%D;%newIDP%>>%outputfile% If "%%E"=="%CurrIDD%" echo %%A;%%B;%%C;%%D;%newIDD%>>%outputfile% If "%%E"=="%CurrIDO%" echo %%A;%%B;%%C;%%D;%newIDO%>>%outputfile% ) ELSE ( echo %%A;%%B;%%C;%%D;%%E>>%outputfile% ) why is Code: [Select] echo %%A;%%B;%%C;%%D;%%E>>%outputfile% in twice?
having two ELSE's won't work i think.
FBThanks for the reply ...
Code: [Select]echo %%A;%%B;%%C;%%D;%%E>>%outputfile%Isn't in twice, it is different on the other line it echos.... Code: [Select]echo %%A;%%B;%%C;%%D;>>%outputfile% Do you know of another way if a double ELSE isn't possible, which makes sense since it doesn't work. Reason for Code: [Select]echo %%A;%%B;%%C;%%D;%%E>>%outputfile% is Anything that doesn't match one of the other statements then plug it back to the file, in other words I don't want to lose something that is custom in the configuration file. how exactly would a double-else work to begin with? The condition is either true, or the condition is false.
I can't evem figure out exactly what you are trying to accomplish with more then one Else, here.
you have,
If "%%E"=="" (... executed when %%E is empty. ) ELSE ( ( ..executed when %%E contains anything. )
ELSE( what conditions do you want this one to execute under? ) Quote ELSE( what conditions do you want this one to execute under? ) The First ELSE STATEMENT is used when it determines that the 5th token has a value and the IF statements are in place to take one ID # and change it to something else.
The final ELSE which can't work ... I need a way to Echo the line even if it doesn't match part of the other criteria so I don't remove something that maybe needed as part of the configuration. Ahhh, I see now;
you have this part of code in the first else:
Code: [Select]If "%%E"=="%CurrIDP%" echo %%A;%%B;%%C;%%D;%newIDP%>>%outputfile% If "%%E"=="%CurrIDD%" echo %%A;%%B;%%C;%%D;%newIDD%>>%outputfile% If "%%E"=="%CurrIDO%" echo %%A;%%B;%%C;%%D;%newIDO%>>%outputfile%
and the last else was intended for if none of these conditions are true. (because, as you said, you want to write something even if none of these do.
I thought about it for a little bit, and came up with a workable solution:
Code: [Select]set %hasoutput%=NO If "%%E"=="%CurrIDP%" ( echo %%A;%%B;%%C;%%D;%newIDP%>>%outputfile% set %hasoutput%=YES } If "%%E"=="%CurrIDD%" ( echo %%A;%%B;%%C;%%D;%newIDD%>>%outputfile% set %hasoutput%=YES ) If "%%E"=="%CurrIDO%" ( echo %%A;%%B;%%C;%%D;%newIDO%>>%outputfile% set %hasoutput%=YES ) if "%hasoutput%"=="NO" then echo %%A;%%B;%%C;%%D;%%E>>%outputfile%
and remove the third else that you have there.This is what I came up with ... Thanks BC_Programmer ... Got it working.
Code: [Select]for /f "tokens=1,2,3,4,5 delims=;" %%A in (%ivlogin%) do ( set hasoutput=NO Echo A:%%A , B:%%B , C:%%C , D:%%D , E:%%E ^& errorlevel:%Errorlevel%>>%log%\PattIDChg.log
If "%%E"=="" ( echo %%A;%%B;%%C;%%D;>>%outputfile% ) ELSE (
If "%%E"=="%CurrIDP%" set hasoutput=YES & echo %%A;%%B;%%C;%%D;%newIDP%>>%outputfile% If "%%E"=="%CurrIDD%" set hasoutput=YES & echo %%A;%%B;%%C;%%D;%newIDD%>>%outputfile% If "%%E"=="%CurrIDO%" set hasoutput=YES & echo %%A;%%B;%%C;%%D;%newIDO%>>%outputfile% If "%hasoutput%"=="NO" echo %%A;%%B;%%C;%%D;%%E>>%outputfile% ) ) pause
|