|
Answer» I haven't been able to find anything online, but I'm using a for loop to step through records in a file. Is there a variable I can set/test to tell me when I've run out of records?
Alternatively, my problem is being caused by the necessity to go out of the loop to execute some code and then come back into the loop. If there's a way to do that, I would appreciate knowing it.FOR %variable IN (set) DO command [command-parameters]
When the FOR command finishes, that means that set has been exhausted. (I.E. every element has been examined).
for /f "delims=," %%R in (record.txt) do ( some command some other command etc. ) REM When you get here, there ain't no records left in the file.
What do you mean about going out of the loop to execute some code and then coming back? Please post some example code.
In the event that anyone cares, here is the code that is finally working. It works whether there is one record or more than one record in the file: (I wrote this to push tnsnames.ora updates to DESKTOPS without knowing what the path would be to the appropriate folder)
REM retrieve all subkeys for the ORACLE INSTALLATION from the REM Windows registry and subset entries with "ORACLE_HOME" REM to a temp file
regedit /e C:\temp\tns_location.txt "HKEY_LOCAL_MACHINE\Software\ORACLE" find "ORACLE_HOME" c:\temp\tns_location.txt > c:\temp\tns_loc.txt
REM there are header rows in the file REM read through the rows in the resulting file until we reach the row that has data in it REM test the record to see if it has data REM parse the record for the data values we seek
for /F "tokens=1-4 delims=/- " %%S in ('date/T') do set DATE=%%V%%T%%U
echo %DATE%
echo "for loop"
for /F "usebackq tokens=1-6 delims=:\=" %%A in ( `FINDSTR /C:"\"ORACLE_HOME\"=" c:\temp\tns_loc.txt`) do ( set drvltr=%%B set dir1=%%C set dir2=%%D set dir3=%%E set dir4=%%F
echo %%B %%C %%D %%E %%F echo %drvltr% %dir1% %dir2% %dir3% %dir4% )
set drvltr2=%drvltr:~1%: echo %drvltr2% %dir1% %dir2% %dir3% %dir4% set ORACLE_HOME=%drvltr2%\%dir1%\%dir2%\%dir3%\%dir4% ECHO %ORACLE_HOME% cd %ORACLE_HOME%\NETWORK\ADMIN copy tnsnames.ora tnsnames.ora.bkp%DATE% copy c:\temp\tnsnames.ora %ORACLE_HOME%\NETWORK\ADMIN
:eof
|