4

I've been trying to list al file paths in my project using PyQgis (I'm not really acquainted with it); my goal is to translate and clip them all to export them to a folder I've tried with:

names =    [layer.name() for layer in QgsProject.instance().mapLayers().values()]

But that only returns the names on the layer panel, I want the full path (and to export it as a csv would be great)

2

1 Answer 1

7

You could use something like the following to get the layer path sources and write the results to a csv:

import csv
layer_paths = [layer.source() for layer in QgsProject.instance().mapLayers().values()]
csv_path = 'path/to/output.csv'

with open(csv_path, 'w', newline='') as csvfile:
    writer = csv.writer(csvfile)
    for paths in layer_paths:
        writer.writerow([paths])

Tested on QGIS 3.4.2 on Win7 64-bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.