HOWTO: Delete a File into the Win95/98 Recycle BinID: Q154005
|
This article describes how to use the Visual Basic function called KILL to enable a user to delete a file from disk. Under Windows 95 or Windows 98, there is an additional feature of deleting files into the Recycle bin, giving a user the ability to reclaim deleted files. The KILL function doesn't offer this to the Visual Basic Programmer, but the SHFileOperation Win32 API does. Below is a code sample showing how to use the API in Visual Basic.
Option Explicit
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias _
"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" (ByVal lpszPath As String, _
ByVal lpPrefixString As String, ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Sub Command1_Click()
Dim FileOperation As SHFILEOPSTRUCT
Dim lReturn As Long
Dim sTempFilename As String * 100
Dim sSendMeToTheBin As String
lReturn = GetTempFileName("c:\", "VB_", 0, sTempFilename)
sSendMeToTheBin = Left(sTempFilename, InStr(sTempFilename, _
Chr$(0)))
With FileOperation
.wFunc = FO_DELETE
.pFrom = sSendMeToTheBin
.fFlags = FOF_ALLOWUNDO
End With
lReturn = SHFileOperation(FileOperation)
MsgBox "View your Recycle Bin for files beginning with VB_"
End Sub
The Win32 SDK Helpfile refers to other SHFileOperation functionality.
Additional query words: kbVBp400 kbVBp500 kbVBp600 kbVBp KBWIN32SDK kbDSupport kbdsd KBAPI
Keywords :
Version :
Platform : NT WINDOWS
Issue type : kbhowto
Last Reviewed: May 25, 1999