I have written a code that imports the different Layers from a folder to QGIS. The problem is that when I run the code again, the layers are duplicated and so on. If I try to remove the layer at the beginning of the code with:
The first time I run the code, I wont work since the layers do not exist yet. To check with layers are in the project, I used this command:
for layer in QgsProject.instance().mapLayers().values():
With this I become a list with the following existing layers:
Is there a way to remove the layers only if they already exist in the project?