1.

Solve : Batch to read a text file line and save as a variable?

Answer»

Hi folks

I am an absolute novice at this, so please bare with me. I am trying to build a batch file that will read a line from a text file and save the text as a variable (say, "variable_name") that I can then use to open a file "variable_name".INP, create a folder called "variable_name", and run a series of other batch commands before looping back around and reading the next line of the text file and repeating the whole process.

This seems like a simple enough task but I am completely overwhelmed by the sea of information out there so any assistance would be very much appreciated.

I have found similar posts on this forum but am struggling to adapt them to my purpose so any suggestions are WELCOME,

Many thanksPerhaps outlining how I want to structure the .bat might make a reply easier and might help me more quickly learn this myself. This what I imagine the basic structure of the batch would be:

1) Open the text file
2) Read line 1
3) Set variable_name to whatever line 1 is
4) Open \path\variable_name.inp
5) Create folder \path\variable_name
5) Run .exe
6) Copy output files to \path\variable_name
7) Return to 2) and read line 2
Repeat until all lines are read

My apologies - I know this may seem lazy, but I would honestly post a first stab at this if I were able to get anything meaningful working, but right now I can't even figure out how read a line and set a variable to the value of a line :-(
It's ok. We just need some more information. Can you show us an example of a few lines of your file?Well, I've been bumbling around for the last few hours and seem to have stumbled BLINDLY upon some MEASURE of SUCCESS. Here is where I stand (please excuse the general inelegance and the especially horrific pathnames - I haven't been able to get variables for paths to work yet:

Code: [Select]FOR /F %%X IN (model_runs.txt) do (

copy "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\Input\time.inps\%%X.inp" "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\Input\"

erase "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\Input\time.inp"

ren "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\Input\%%X.inp" time.inp

mkdir "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\Output\%%X"

cd "C:\Users\Stuart Muller\Documents\Visual Studio 2008\Projects\FTLOADDSaRSE_v2.4 - Copy\FTLOADDS_Test_Case_v3\FTLOADDS\"

run2.bat

"C:\Program Files\Golden Software\Surfer 9\Scripter\Scripter.exe" "C:\Program Files\Golden Software\Surfer 9\Samples\Scripts\Stu_MultiContMaps.bas"

)
pause
Not too bad for an imbecile



Discussion

No Comment Found