<div dir="ltr">Dear all,<div><br></div><div>I have some troubles wher I use in a pyqgis the function</div><div>QgsVectorFileWriter.deleteShapeFile(file_path)</div><div>here below the example:</div><div><pre style="white-space:pre-wrap;background-color:rgb(43,43,43);color:rgb(169,183,198);font-family:"JetBrains Mono",monospace"><span style="color:rgb(204,120,50)">def </span><span style="color:rgb(255,198,109)">removeLayer</span>(path_layer):<br>    <span style="color:rgb(128,128,128)"># remove layer from TOC if already loaded<br></span><span style="color:rgb(128,128,128)">    </span>basefile = os.path.basename(path_layer)<br>    diff_layer = os.path.splitext(basefile)[<span style="color:rgb(104,151,187)">0</span>]<br>    <span style="color:rgb(114,115,122)">directory </span>= os.path.dirname(path_layer)<br>    <span style="color:rgb(114,115,122)">extensions </span>= [<span style="color:rgb(106,135,89)">"shp"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"shx"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"dbf"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"prj"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"sbn"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"sbx"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"fbn"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"fbx"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"ain"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"aih"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"ixs"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"mxs"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"atx"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"xml"</span><span style="color:rgb(204,120,50)">,<br></span><span style="color:rgb(204,120,50)">                  </span><span style="color:rgb(106,135,89)">"cpg"</span><span style="color:rgb(204,120,50)">, </span><span style="color:rgb(106,135,89)">"qix"</span>]<br>    output_path=path_layer<br>    <span style="color:rgb(204,120,50)">if </span>os.path.exists(path_layer):<br>        <span style="color:rgb(204,120,50)">if </span><span style="color:rgb(136,136,198)">len</span>(QgsProject.instance().mapLayersByName(diff_layer)) > <span style="color:rgb(104,151,187)">0</span>:<br>            lyr = QgsProject.instance().mapLayersByName(diff_layer)[<span style="color:rgb(104,151,187)">0</span>]<br>            <span style="color:rgb(136,136,198)">print</span>(<span style="color:rgb(106,135,89)">'renaming layer1: '</span><span style="color:rgb(204,120,50)">, </span><a href="http://lyr.id/" target="_blank">lyr.id</a>())<br>            QgsProject.instance().removeMapLayer(<a href="http://lyr.id/" target="_blank">lyr.id</a>())<br><br>        QgsVectorFileWriter.deleteShapeFile(path_layer)</pre></div><div>Often some handles still remains and I'm not able to delete .dbf and .shp files</div><div>How can I solve this error?</div><div><br></div><div>Thanks</div><div>Pierluigi</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">Ing. Pierluigi De Rosa (PhD in Earth Science)</div><div dir="ltr">Contract Professor of Geographic Information System at University of Perugia<br>cel: 349755826<span><span dir="ltr">8</span></span> / fax: 075 7823038<br>skype: pierluigi.derosa </div></div></div></div></div></div></div>