fobj = open(os.path.join(loc,index.text), “w+”)
/* note: in the above line of code I have used os.path.join to build a path that contains the file name which is a better way of building the file path instead of overloading “+” operator.*/
# saving the index to this index.txt file
for index, each in enumerate(files):
if index != 0:
fobj.write(str(index)+” ”+ each.split("-")[-1].split(".")[0]+”\\n”)
# close the file
fobj.close()