|
-
Aug 19th, 2005, 03:40 AM
#1
Thread Starter
Fanatic Member
[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..
-
Aug 19th, 2005, 03:46 AM
#2
Frenzied Member
Re: deleting a file in single button?
the Kill function?
VB Code:
Private sub cmdDeleteFile_Click
On error resume next
Kill app.path & "\Myapp.exe"
On error goto 0
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:
Public Function fDeleteFile(strFilename as string) as Boolean
On error goto ErrHandler
Kill strFilename
fDeletefile = true
Exit function
ErrHandler:
fDeleteFile = false
End Function
' You can use this function like:
If fDeletefile(app.path & "\MyApp.exe") then
Msgbox "File MyApp was deleted.", vbOkOnly + VbInformation, "Deletion"
else
Msgbox "File MyApp was not deleted due to error: " & err.description, vbOkOnly + VbCritical, "Deletion"
end if
-
Aug 19th, 2005, 04:48 AM
#3
Re: deleting a file in single button?
 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).
-
Aug 19th, 2005, 04:50 AM
#4
Re: deleting a file in single button?
My SHFileOperation example if you're interested.
-
Aug 19th, 2005, 05:28 AM
#5
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|