AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > VB编程

在VB程序中通过回收站删除文件

51自学网 http://www.wanshiok.com
在标准工程中添加一个公共对话框和两个按钮即可尝试本例:

Option Explicit

'删除文件的API
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As ToBin) As Long
'清空回收站的API
Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long

Private Type ToBin
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type

Const FO_DELETE = &H3
Const FOF_ALLOWUNDO = &H40
Const SHERB_NORMAL = &H0

'将文件移至回收站
Private Sub Command1_Click()
Dim Go As ToBin
Dim strFile As String
With CommonDialog1
.Filter = "(*.bak)|*.bak"
.DialogTitle = "删除文件"
.ShowOpen
strFile = .FileName
End With

With Go
.wFunc = FO_DELETE
.pFrom = strFile
.fFlags = FOF_ALLOWUNDO
End With

SHFileOperation Go
End Sub

'清空回收站
Private Sub Command2_Click()
Dim RetVal As Long
RetVal = SHEmptyRecycleBin(0&, vbNullString, SHERB_NORMAL)
End Sub

 

 

 
上一篇:检测磁盘类型的信息  下一篇:VB数组小技巧一则