Make your own free website on

      API Tip

DeleteFile - API makes Your programs run faster and smoother since it doesn't need to go through VB run-time for processing. Take this as Your advantage and use to delete files right from Your apps!


Declaration of DeleteFile function in Visual Basic:

Public Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

    lpFileName  - full path of the file You want to delete.

As the name implies, DeleteFile function deletes the file on Your hard disk. If the function succeeds, it returns non-zero value. If it fails, the return value is 0. To delete the file You also have to have delete permission on the file or delete child permission in the directory. In Windows9x, file will be deleted even if it is open for normal I/O or as memory-mapped file. In WindowsNT/2000, the function fails if the file is open for normal I/O or as a memory-mapped file.

This is quite handy function if Your application performs file manipulation. Make sure to prevent accidental deletion of files by at least implementing warning messages. The example on how to use this function:

    Private Sub cmdDelete_Click()

      dim temp As Long

      temp=DeleteFile(c:/      'deletes the file "c:\"

End Sub

Api Tips - Home


Made By Laimonas Simutis. 2001.