In the Browser it's not possible to delete shapefiles. In ArcMap you can delete shapefiles easily within the ArcCatalog.

How can I delete shapefiles in QGIS without minimizing the QGIS Window, navigating to the folder on my computer, select all the files that belong to a shapefile (shp, dbf, shx, prj, etc.) and delete it?

  • Are you using QGIS Browser, or QGIS Desktop? Commented Apr 20, 2016 at 8:30
  • I use QGIS Desktop. Commented Apr 20, 2016 at 8:34
  • 2
    Doesn't seem to be possible in the GUI, and IMO that's appropriate. Commented Apr 20, 2016 at 12:21
  • You can install ArcGis - in ArcGisCatalog select the file and press >delete<
    – frmante
    Commented Oct 27, 2016 at 1:27
  • Where can I download ArcGIS with ArcCatalog ready to install and use, @frmante? Commented Oct 27, 2016 at 2:03

5 Answers 5


There is a built-in function for this in the QGIS API.

Select your layer in the Layers panel, then open the Python console and run the following:

from qgis.core import QgsVectorFileWriter

layer = iface.activeLayer() # If no layer selected, it will be empty and make the end of the script failed
shp_path = layer.dataProvider().dataSourceUri().split('|')[0]
print (QgsVectorFileWriter.deleteShapeFile(shp_path)) # Should return True if really deleted

In my QGIS 3.14 this seems to be implemented. Using the integrated "Browser", you have the option to right-click -> Delete File.

This will also remove .dbf, .prj and .shx for a selected .shp-File.

QGIS Delete File for shapefile

I have been waiting for this as well and am glad that it finally works like ArcMap Catalog. The feature request to delete directly via layer (delete the source-file of a layer) mentioned below this answer is still pending though.


Not sure if you can do this using the GUI but you can certainly do this using the Python Console. The following code goes into the specified path and deletes all files beginning with "File_Name":

import glob, os
path = 'path/to/folder//'

for fname in glob.glob(path + "File_Name.*"):


Responding to the comment from @GermánCarrillo, you should enter the filename in full and then add a . at the end as shapefiles (in most cases atleast) end with different extensions after the .. So now there should be less chance of you deleting shapefiles which contain similar names.

  • 3
    That could be a bit dangerous. You might want to delete a file whose name turns out to be a prefix for other files, e.g., deleting "boundary" while having "boundary_country" in the same folder. Commented Apr 20, 2016 at 20:53
  • 1
    @GermánCarrillo - Indeed it could be, I've edited the post to include a minor addition which should help a little to avoid deleting other files with similar names =)
    – Joseph
    Commented Apr 21, 2016 at 9:29

Building on Joseph's answer, you can delete any file in the Python console.

This is a little script that will delete all the files with a shapefile-associated extension in the directory of the 'foo.shp' file you give it:

import os, argparse

def deleteShapefile(aDir, aFile):

    fnameNoExt = os.path.splitext(aFile)[0]

    extensions = ["shp", "shx", "dbf", "prj", "sbn", "sbx", "fbn", "fbx", "ain", "aih", "ixs", "mxs", "atx", "xml", "cpg", "qix"]

    theFiles = [f for f in os.listdir(aDir) if os.path.isfile(os.path.join(aDir, f))] # get list of all files in that directory

    for f in theFiles:
        theFile = os.path.basename(f)
        name, extension = os.path.splitext()
        # If the name matches the input file and the extension is in that list, delete it:
        if (name == fnameNoExt or name == fnameNoExt + ".shp") and (extension in extensions): # handles the foo.shp.xml case too.
            os.remove f

def main():
    parser = argparse.ArgumentParser(description="A path to a file assumed to be a shapefile, this deletes all files in the same directory that have extensions possible in shapefile subfiles.")
    args = parser.parse_args()
    realpath = os.path.realpath(args.SHAPEFILENAME)
    theDir, theFile = os.path.split(realpath)

if __name__ == '__main__':

You could run that in a command terminal if you saved it as a .py file with something like

$ python deleteshapefile.py myshapefile.shp

If you find yourself doing it a lot, you could put that .py file somewhere on the path given in your environment variable PYTHON_PATH and just import it in the console inside QGIS, in which you just call deleteShapefile(aDir, aFile).


You could also do this using the terminal and appropriate use of wildcards. For example, in bash running:

rm 'path/to/file'.*

will erase all the shapefile associated files for a particular file. It can be a bit dangerous though if you're not careful. I always try to be good and run the ls command (e.g., ls 'path/to/file'.*) to return a list of all files captured by the wildcard before removing them (for example, if you happen to have a .tif with the same file name that you don't want to erase as well).

That'd probably make a good feature request though!

  • Feature Request raised, though I figured the code from various answers would vary a little with the changes to QGIS 3. Qt5, PyQt 5, Python 3 ect... Delete layers/files rather than remove
    – maskin
    Commented Sep 12, 2018 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.