I'm trying to run a batch of commands from a .txt file using python. ("cmd.batch.txt" = ~1000 command lines :
perl cmd.1.pl -in -parameters)

and redirect renamed output files to new folders. It works fine for the first line, but I'm having trouble getting something to loop through all of the commands in "cmd.batch.txt".

Any help would be much appreciated !

import os

while True:
w=y.split(" ")
for fn in os.listdir("."):
if fn[-5:] == "ML.dS":
os.rename(fn, "./dS/"+ w[1] +"ML.dS")
if fn[-5:] == "NG.dS":
os.rename(fn, "./dS/"+ w[1] + "NG.dS")
if not x: break

There are two problems

while True:
You read the entire file on every loop, so you willl always get the first rec of the newly read list.

if not x: break
This may exit if you have any blank lines in the file.

Instead, you want to loop through all of the records with a for() loop

for rec in input_list:
    print rec
    if len( rec.strip() ) < 1:
        print "     that rec  was an empty line"

Thanks so much for your help! It worked!!
Now it is going line by line through the command list -

But, I have another problem which is the program outputs files with the same basename so they are overwritten everytime the program runs. I have written the following code to change the basenames of the output files when they are written to the directory. But, it only works for the first couple of files - what's the best way to modify this portion of the code to keep it looping ?
Thanks again-

for rec in input_list:
for fn in os.listdir("."):
if fn[-5:] == "ML.dS":
os.rename(fn, "%01iML.dS" %count)

If you want something to keep looping couldn't you just wrap it up in a while loop?
While count < somenumber:
do these things