TransWikia.com

Deleting shapefile python (lock?) (QGIS 3.10)

Geographic Information Systems Asked by Louis Cottereau on September 3, 2020

I have trouble with deleting shapefiles and notice a weird behavior when I am running my scripts
(Version QGIS 3.14.15-Pi)

layer = iface.activeLayer()
path_layer = layer.source()
cloned_layer = clone_vl(layer) # makes a memory layer and copies crs, features, attributes, ...
QgsProject.instance().removeMapLayer(layer.id())
del layer
print(QgsVectorFileWriter.deleteShapeFile(path_layer))

returns False if I run it as a script inside the Python console editor of QGIS
but return True if I execute it line after line directly in the console.

Which seems like something weird is going on, like if I execute the script, QGIS doesn’t have the ‘time’ to unlock the shapefile or something.

What is going on?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP