1

This is a follow-up question to an answer to Deleting Shapefiles using QGIS?

I tried to run the script, however it always returns False and the shapefile is not deleted - any ideas what needs to be changed in order to make it work?

This is what it looks like:

    layer = iface.activeLayer()
    layer
    <qgis._core.QgsVectorLayer object at 0x0000000012DFC1E0>
    shp_path = layer.dataProvider().dataSourceUri().split('|')[0]
    shp_path
    u'C:/GIS/GIS_Kirchenkreise/13 GIS/Grundlagen/Daten_aufbereitet/Wahlkreise_Test.shp'
    print (QgsVectorFileWriter.deleteShapeFile(shp_path))
    False
Stephanie
  • 11
  • 3
  • 1
    Tested on GNU/Linux with QGIS 2.18 and works like a charm. Is the Shapefile open by another program (other programs may lock the Shapefile)? Do you have read AND write permissions on that folder/file? – Germán Carrillo Oct 27 '16 at 11:50
  • 1
    Thanks @Germán for testing! I work with QGIS 2.14 (Windows) and I think I have all permissions and no other programs locking the shapefile. Running the script again I realised that the prj, the qpj and the shx files are deleted, however the dbf and the shp files remain. I guess that at least something is happening – Stephanie Nov 04 '16 at 09:33
  • Testet with QGIS 2.14 (Windows) works fine too. – EikeMike Apr 19 '17 at 13:14
  • I have the same issue @Stephanie : .prj, .qpj and .shx are deleted but .shp and .dbf remain. I'm using QGIS 3.10.2 – GeoGyro Apr 07 '20 at 12:52

0 Answers0