Why does 'cycleNumber' not count above 10?
import os
cycleNumber = 1
for files in os.listdir('Cycles'):
if files.startswith('Cycle' + str(cycleNumber)):
cycleNumber += 1
You are only iterating over the list returned from os.listdir() (which is not in any particular order) once. This means that if the files were given in an unexpected order such as:
Cycle2.txt
Cycle1.txt
Then it would take till the second iteration for the cycleNumber to increment from 1 to 2, but by then you have already gone passes Cycle2.txt!
Instead, you should use a while loop:
import os
cycleNumber = 0
while any(f.startswith('Cycle' + str(cycleNumber+1)) for f in os.listdir('Cycles')):
cycleNumber += 1
A test:
$ mkdir Cycles
$ for i in {1..11}; do touch Cycles/Cycle$i.txt; done;
$ python -q
>>> import os
>>> cycleNumber = 0
>>> while any(f.startswith('Cycle' + str(cycleNumber+1)) for f in os.listdir('Cycles')):
... cycleNumber += 1
...
>>> cycleNumber
11
os.listdir()is not sorted numerically as you think.