Chris or Leslie Smith wrote: > I just did this :-) What I did was > > 1) use the glob module to get a list of the files in the directory (*.htm) > 2) sort this using a special sort function (in my case the files were named > as #_# where # was a number and I wanted to sort according to the first > number and subsort according to the second) > 3) then I just stepped through the list using enumerate and used the index to > find the next and previous names in the list, e.g. >
You have a couple of errors in your conditionals > #### > for i, fil in enumerate(flist): > if i<>1: > prev = flist[i-1] This should be 'if i >= 1'. If i==0 your condition will be true and you will set prev = flist[-1] which is the *last* item in flist. > #do previous link > if i<> len(flist): > next = flist[i+1] should be 'if i+1 < len(flist)' to avoid an IndexError on the last element. Kent > #do next link > #### > > /c > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor