Results 1 to 6 of 6

Thread: Difference Between DeleteFile API and Kill Function?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Difference Between DeleteFile API and Kill Function?

    Is There a Difference Between the DeleteFile API and the Kill Function?

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Difference Between DeleteFile API and Kill Function?

    I may be wrong here (guessing) but I think with the API you can send the file to recycle bin.

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Difference Between DeleteFile API and Kill Function?

    There is practically no difference except that DeleteFile() requires special declaration. Also, DeleteFile() will NOT generate any errors if file doesn't exist and Kill statement will ... so maybe that's the only advantage.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: Difference Between DeleteFile API and Kill Function?

    Does anyone know how to delete hidden files without having to change the attributes?

  5. #5
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Difference Between DeleteFile API and Kill Function?

    not 100% sure if you can do that. setting the attributes in VB is easy tho.

    Private Sub Command1_Click()
    On Error GoTo KillErr:
    SetAttr "C:\filename.txt", vbNormal
    Kill "C:\filename.txt"
    Exit Sub

    KillErr:
    If Err Then MsgBox Err.Description
    End Sub
    When your dreams come true.
    On error resume pulling hair out.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Difference Between DeleteFile API and Kill Function?

    DeleteFile() returns zero if an error occurs, such as if the file does not exist. If it matters to you, you must trap the return value.
    VB Code:
    1. Dim lRet As Long
    2. lRet = DeleteFile([filename])
    3. If (lRet) Then
    4.     ' succeeded
    5.   Else
    6.     ' didn't
    7. End If

    To delete a file with the option to send it to the recycle bin you must use the SHFileOperation() API.
    VB Code:
    1. Declare Function SHFileOperation Lib "shell32" Alias "SHFileOperationA" ( _
    2.     ByRef lpFileOp As SHFILEOPSTRUCT _
    3. ) As Long
    4.  
    5. Private Type SHFILEOPSTRUCT
    6.     hWnd        As Long
    7.     wFunc       As Long
    8.     pFrom       As String
    9.     pTo         As String
    10.     fFlags      As Integer
    11.     fAborted    As Boolean
    12.     hNameMaps   As Long
    13.     sProgress   As String
    14. End Type
    15.  
    16. Const FOF_ALLOWUNDO = &H40
    17. Const FOF_NOCONFIRMATION = &H10
    18. Const FO_DELETE = &H3
    19.  
    20. ' Usage: -------------------------------------
    21. Dim udtFileOp   As SHFILEOPSTRUCT
    22. With udtFileOp
    23.     .wFunc = FO_DELETE
    24.     ' pFrom is a null-delimited string containing the files to delete.
    25.     ' In addition, the final filename must have an extra null char after it.
    26.     .pFrom = [filename] & vbNullChar & vbNullChar
    27.     ' add Or FOF_NOCONFIRMATION to suppress the Are You Sure box.
    28.     .fFlags = FOF_ALLOWUNDO
    29. End With
    30.  
    31. ' Perform the delete
    32. Dim lRet        As Long
    33. lRet = SHFileOperation(udtFileOp)
    34. If (lRet) Then
    35.     ' An error occured
    36. End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width