[QGIS-Developer] deleteShapefile in pyqgis
pierluigi de rosa
pierluigi.derosa at gmail.com
Tue Feb 22 09:06:55 PST 2022
Dear all,
I have some troubles wher I use in a pyqgis the function
QgsVectorFileWriter.deleteShapeFile(file_path)
here below the example:
def removeLayer(path_layer):
# remove layer from TOC if already loaded
basefile = os.path.basename(path_layer)
diff_layer = os.path.splitext(basefile)[0]
directory = os.path.dirname(path_layer)
extensions = ["shp", "shx", "dbf", "prj", "sbn", "sbx", "fbn",
"fbx", "ain", "aih", "ixs", "mxs", "atx", "xml",
"cpg", "qix"]
output_path=path_layer
if os.path.exists(path_layer):
if len(QgsProject.instance().mapLayersByName(diff_layer)) > 0:
lyr = QgsProject.instance().mapLayersByName(diff_layer)[0]
print('renaming layer1: ', lyr.id())
QgsProject.instance().removeMapLayer(lyr.id())
QgsVectorFileWriter.deleteShapeFile(path_layer)
Often some handles still remains and I'm not able to delete .dbf and .shp
files
How can I solve this error?
Thanks
Pierluigi
--
Ing. Pierluigi De Rosa (PhD in Earth Science)
Contract Professor of Geographic Information System at University of Perugia
cel: 3497558268 / fax: 075 7823038
skype: pierluigi.derosa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220222/c5deab33/attachment.html>
More information about the QGIS-Developer
mailing list