foryinyears:# years list is created above and contain all years from start to end year
# Delete files if existing
fn=str(cwd)+"\\OF_"+str(y)+".txt"
ifos.path.isfile(fn):
os.remove(fn)
forninnib_liste:# sort the nib_liste alphabetically
foryearinyears:
ifyearinn.split():
ify==year:
withopen(str(cwd)+'\\OF_'+str(year)+'.txt','a',encoding='utf-8')asf:# a = append to textfile
f.write(str(n)+'\n')# write the OF-project for the specific year to the textfile
else:
# Delete file if existing
fn=str(cwd)+"\\OF_all.txt"
ifos.path.isfile(fn):
os.remove(fn)
withopen(str(cwd)+'\\OF_all.txt','w',encoding='utf-8')asf:# w = write - will overwrite any existing content https://www.w3schools.com/python/python_file_write.asp
forninnib_liste:
f.write(str(n)+'\n')# write the all OF-projects to the textfile
# Show message
self.iface.messageBar().pushMessage("Success","List with Nib-projects saved to file",level=Qgis.Success,duration=3)