Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to delete files .shp and .dbf using python code (removeMapLayers, deleteShapeFile) #39428

Closed
DG-85 opened this issue Oct 16, 2020 · 4 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Feedback Waiting on the submitter for answers PyQGIS Related to the PyQGIS API stale Uh oh! Seems this work is abandoned, and the PR is about to close.

Comments

@DG-85
Copy link

DG-85 commented Oct 16, 2020

Describe the bug

It looks like the simple code below does not work as expected. In my plugin "deleteShapeFile" results always in "False".
All files will be deleted except .shp and .dbf. They are somehow still in use.

The same problem is also mentioned here: https://gis.stackexchange.com/questions/376765/unable-to-delete-shp-and-dbf-files-from-directory-when-on-canvas-pyqgis

How to Reproduce

    aLayer = self.iface.activeLayer()                            
    shp = str(aLayer.publicSource())                             
    j=shp.find("|")                                              
    if j > -1:                                                   
     shp = shp[:j]                                               
    QgsProject.instance().removeMapLayers([aLayer.id()])         
    ret = QgsVectorFileWriter.deleteShapeFile(shp)               
    QMessageBox.warning(self.iface.mainWindow(),"ret", str(ret) )

QGIS and OS versions
3.14.1-Pi and Windows 10 (64-bit)

Additional context

@DG-85 DG-85 added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Oct 16, 2020
@gioman
Copy link
Contributor

gioman commented Oct 16, 2020

@DG-85you should ask in the developers ML if you are doing it right, rather than assuming that is a bug (maybe it is, but better check first with the gurus).

@gioman gioman added the PyQGIS Related to the PyQGIS API label Jan 3, 2021
@alexbruy
Copy link
Contributor

alexbruy commented Feb 3, 2022

Can't reproduce on both Linux and Windows.

@alexbruy alexbruy added the Feedback Waiting on the submitter for answers label Feb 3, 2022
@github-actions
Copy link

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale".
If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue.
In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue.
If there is no further activity on this issue, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Feb 18, 2022
@github-actions
Copy link

While we hate to see this happen, this issue has been automatically closed because it has not had any activity in the last 42 days despite being marked as feedback. If this issue should be reconsidered, please follow the guidelines in the previous comment and reopen this issue.
Or, if you have any further questions, there are also further support channels that can help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Feedback Waiting on the submitter for answers PyQGIS Related to the PyQGIS API stale Uh oh! Seems this work is abandoned, and the PR is about to close.
Projects
None yet
Development

No branches or pull requests

3 participants