I have several .qgz project in different directories. I would like to get all the (displayed) layer names from each project. I tried several forms of code to get it from documentation, but it only returns an empty list in each file.
for settlement in os.listdir(source):
settlement_path = os.path.join(source, str(settlement))
settlement_name = str(settlement)
for qgz in os.listdir(settlement_path):
if str(qgz).endswith('.qgz'):
project = QgsProject.instance()
project.read(str(qgz))
layers_names = []
for layer in project.mapLayers().values():
layers_names.append(layer.name())
print(layers_names)
project.clear()
qgz
) is correct?project.mapLayers()
?