Results 1 to 5 of 5

Thread: [RESOLVED] deleting a file in single button?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    Resolved [RESOLVED] deleting a file in single button?

    hi, how to delete a file in single button?

    lets say i want to delete a Myapp.exe using a single button in vb...

    and Myapp.exe not showing anymore in recycle bin

    thanks..

  2. #2
    Frenzied Member Devion's Avatar
    Join Date
    Sep 2000
    Location
    The Netherlands
    Posts
    1,049

    Re: deleting a file in single button?

    the Kill function?

    VB Code:
    1. Private sub cmdDeleteFile_Click
    2.     On error resume next
    3.           Kill app.path & "\Myapp.exe"
    4.     On error goto 0    
    5. end Sub

    The on Error traps are in place for the fact that if MyApp can't be deleted it will raise an error. Resume next will ignore the error, On error goto 0 will allow errors to be raised.

    A better way of doing it:

    VB Code:
    1. Public Function fDeleteFile(strFilename as string) as Boolean
    2.     On error goto ErrHandler
    3.         Kill strFilename
    4.         fDeletefile = true
    5.         Exit function
    6. ErrHandler:
    7.         fDeleteFile = false
    8. End Function
    9.  
    10. ' You can use this function like:
    11. If fDeletefile(app.path & "\MyApp.exe") then
    12.    Msgbox "File MyApp was deleted.", vbOkOnly + VbInformation, "Deletion"
    13. else
    14.    Msgbox "File MyApp was not deleted due to error: " & err.description, vbOkOnly + VbCritical, "Deletion"
    15. end if

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

    Re: deleting a file in single button?

    Quote Originally Posted by nokmaster
    and Myapp.exe not showing anymore in recycle bin
    Not sending it to the Recycle Bin, or sending it?

    If not, use Kill like Devion posted.
    If yes, use SHFileOperation (I posted an example earlier).

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

    Re: deleting a file in single button?

    My SHFileOperation example if you're interested.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2002
    Location
    Philippines
    Posts
    877

    Re: deleting a file in single button?

    @Devion

    thanks...

    works perfect

    br,

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