We have around 500 files in different folders. For QC purpose, we've selected 25 files(we have the list of files/path in excel) out of those 500. Is it possible to open all those 25 files(it might be a shp or tab) in one shot using the file path in excel sheet ?


You can use something like the following code in the Python Console which:

  1. Reads the first column and gets the path
  2. Removes the extension (in this case, the .shp) so that it's not included when adding the layer into QGIS
  3. Adds the layer to QGIS

    import csv, os
    mycsv = csv.reader(open("path/to/csv"))
    for row in mycsv:
        layer_path = row[0]
        layer_name = os.path.basename(layer_path.replace('.shp', ''))
        iface.addVectorLayer(layer_path, layer_name, "ogr")
  • Thanks a lot mate. Worked like a charm. One question. The folder has has dxf, tab & shp files. So will it load irrespective of the extension ? – joseph_k Apr 21 '16 at 11:35
  • 1
    @saravanaganesh18 - Most welcome buddy! I just tested it on tab and dxf files and yes, it will load them. Note however that when loading dxf, it will prompt you to select which geometry type layers you want added. – Joseph Apr 21 '16 at 11:43

Your Answer

