Results 1 to 6 of 6

Thread: How to delete files...

  1. #1

    Thread Starter
    Member DoomBringer's Avatar
    Join Date
    Aug 2001
    Location
    Sweden
    Posts
    34

    Unhappy How to delete files...

    How to delete a file with VB using API?

    PLZ. help us...

    //DoomBringer

  2. #2
    Lively Member
    Join Date
    Aug 2001
    Posts
    72
    Why not just use VB's Kill command? But if you have to use an API call, there's...

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

    Hopefully there's nothing funky about it, but I've never used it -- just looked it up so I can't promise anything.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VBs Kill command is the easiest, but another alternate would be to use the DeleteFile method of the FileSystemObject.

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Well i would not reccomend using the FileSystemObject just for deleting a file.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  5. #5
    DaoK
    Guest
    kill command work like that :

    kill ("c:\myproject.exe")
    is that how we use it ?

  6. #6
    Megatron
    Guest
    Kill will delete the file, but not send it to the recycle bin. If you want to send it to the Recycle Bin, then you could use the SHFileOperation API.
    VB Code:
    1. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    2. Private Type SHFILEOPSTRUCT
    3.     hwnd As Long
    4.     wFunc As Long
    5.     pFrom As String
    6.     pTo As String
    7.     fFlags As Integer
    8.     fAnyOperationsAborted As Long
    9.     hNameMappings As Long
    10.     lpszProgressTitle As String
    11. End Type
    12. Private Const FO_DELETE = &H3
    13. Private Const FOF_ALLOWUNDO = &H40
    14.  
    15. Private Sub Command1_Click()
    16.  
    17.     Dim SH As SHFILEOPSTRUCT
    18.     SH.hwnd = hwnd
    19.     SH.wFunc = FO_DELETE
    20.     SH.fFlags = FOF_ALLOWUNDO
    21.     SH.pFrom = "C:\Windows\Desktop\MyFile.txt"
    22.     SHFileOperation SH
    23.    
    24. End Sub

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