Click to See Complete Forum and Search --> : How to delete files...
DoomBringer
Sep 7th, 2001, 08:03 AM
How to delete a file with VB using API?
PLZ. help us...
//DoomBringer
JDYoder
Sep 7th, 2001, 08:25 AM
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.
Hack
Sep 7th, 2001, 08:47 AM
VBs Kill command is the easiest, but another alternate would be to use the DeleteFile method of the FileSystemObject.
Vlatko
Sep 7th, 2001, 09:04 AM
Well i would not reccomend using the FileSystemObject just for deleting a file.
DaoK
Sep 9th, 2001, 01:11 PM
kill command work like that :
kill ("c:\myproject.exe")
is that how we use it ? :confused:
Megatron
Sep 9th, 2001, 01:13 PM
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.
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Sub Command1_Click()
Dim SH As SHFILEOPSTRUCT
SH.hwnd = hwnd
SH.wFunc = FO_DELETE
SH.fFlags = FOF_ALLOWUNDO
SH.pFrom = "C:\Windows\Desktop\MyFile.txt"
SHFileOperation SH
End Sub
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.