delete shapefile from folder

1761
4
07-25-2012 01:52 PM
by Anonymous User
Not applicable
Original User: helenchu

All:

How to delete a shapefile from a local folder in vb.net?  I hope I don't have to check one by one file's extension to delete it. 
Thank you for your help.
0 Kudos
4 Replies
by Anonymous User
Not applicable
Original User: helenchu

Never mind.  I already found out how to do it.  Thanks all.
0 Kudos
JORGELAGOS2
New Contributor
Never mind.  I already found out how to do it.  Thanks all.


Could you please tell me how?

Thanks

Jorge
0 Kudos
by Anonymous User
Not applicable
Original User: helenchu

Hi Jorge,

Sorry I didn't see your question till now. 
Below is my function to delete shapefile just in case you still need it.


    Function DeleteExisting(ByVal strFileSpec As String) As Boolean


        DeleteExisting = True
        If Dir(strFileSpec) <> "" Then
            Debug.Print("deleting : " & strFileSpec)


            Dim pFSO As New Scripting.FileSystemObject
            pFSO.DeleteFile(strFileSpec, True)
            If Dir(strFileSpec) <> "" Then
                DeleteExisting = False
                Debug.Print("unable to delete: " & strFileSpec)
            End If
        End If


        Exit Function
    End Function
0 Kudos
DuncanHornby
MVP Notable Contributor
Your code example is simply deleting a file but a shapefile is composed of at least 3 files.

This is not a good way to delete a spatial dataset. You should be using the IDataset Interface or the calling the Delete Geo-processing tool.

Duncan
0 Kudos