|
-
Sep 7th, 2001, 08:03 AM
#1
Thread Starter
Member
How to delete files...
How to delete a file with VB using API?
PLZ. help us...
//DoomBringer
-
Sep 7th, 2001, 08:25 AM
#2
Lively Member
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.
-
Sep 7th, 2001, 08:47 AM
#3
VBs Kill command is the easiest, but another alternate would be to use the DeleteFile method of the FileSystemObject.
-
Sep 7th, 2001, 09:04 AM
#4
Frenzied Member
Well i would not reccomend using the FileSystemObject just for deleting a file.
-
Sep 9th, 2001, 01:11 PM
#5
kill command work like that :
kill ("c:\myproject.exe")
is that how we use it ?
-
Sep 9th, 2001, 01:13 PM
#6
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:
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
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
|