I want to loop through folders and find shapefiles which contains the name "GST" and merging them together using python in QGIS 3.4.3.
In detail: The folder x contains four folders called VA72, VA73, VA75 and VA76. In each of this folders where a lot other folders (72001, 72002, a.s.o.). In each of them are three other folders, one of them is called "SHP". And in this folder there are several shapefiles. One of the shapefiles is called 72001GST_V2.shp. In every folder (VA72, VA73, VA75 and VA76) the structure is the same.
I want to select all shapefile layers which contain the phrase "**GST_*.shp" and merge them together.
I tried a code I've found after modified it, but after performing it nothing happens.
The code is as follows:
import os
import processing
import glob
Select_folder="C:/*/"
Save_results= "C:/*/merged"
layers = "*GST_*.shp" #select only shapefile layers that contain the phrase GST
os.chdir(Select_folder)
# loop through folders and merge them together
for layers in glob.glob( Select_folder ):
processing.run("native:mergevectorlayers", {'INPUT':[layers],'CRS':QgsCoordinateReferenceSystem('EPSG:31255'),'OUTPUT':[Save_results+'/'+'GST.shp']})
## load merged GST layer
GST_merged = QgsVectorLayer('C:/*/merged','GST','ogr')
QgsProject.instance().addMapLayer(GST_merged, True)
What is wrong? Has anybody an idea?