Kill Statement

Named Arguments

No

Syntax

Kill pathname


pathname

Use: Required

Data Type: String

The file or files to be deleted.

Description

Deletes a file from disk.

Rules at a Glance

  • If pathname doesn't include a drive letter, the folder and file are assumed to be on the current drive.

  • If pathname doesn't include a folder name, the file is assumed to be in the current folder.

  • You can use the multiple-character (*) and single-character (?) wildcards to specify multiple files to delete.

  • If the file is open or is set to read-only, an error is generated.

Programming Tips and Gotchas

  • Note that in the Windows 95 and NT environments, the deleted file isn't placed in the Recycle Bin. However, the following code demonstrates how to use the FileOperation API found in Shell32.DLL to move a file to the Windows 95 Recycle Bin or the NT4 Recycler:

    Option Explicit
    
    'declare the file operation structure
    Type SHFILEOPSTRUCT
        hWnd As Long
        wFunction As Long
        pFrom As String
        pTo As String
        fFlags As Integer
        fAborted As Boolean
        hNameMaps As Long
        sProgress As String
    End Type
    
    'declare two constants needed for the delete operation
    Private Const FO_DELETE = &H3
    Private Const FO_FLAG_ALLOWUNDO = &H40
    
    'declare the API call function
    Declare Function SHFileOperation Lib "shell32.dll" _
              Alias "SHFileOperationA" _
              (lpFileOp As SHFILEOPSTRUCT) As Long
    
    
    Public Function WinDelete(sFileName As String) As Long
        'create a copy of the file operation structure
        Dim SHFileOp As SHFILEOPSTRUCT
    
        'need a Null terminating string
        sFileName = sFileName & vbNullChar
        
        'assign relevant values to structure
        With SHFileOp
            .wFunction = FO_DELETE
            .pFrom = sFileName
            .fFlags = FO_FLAG_ALLOWUNDO
        End With
        
        'pass the structure to the API function
        WinDelete = SHFileOperation(SHFileOp)
    
    End Function

  • Use the RmDir statement to delete folders.

See Also

RmDir Statement
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.67.177