VB 版 (精华区)
发信人: Friend (沙漠绿洲), 信区: VisualBasic
标 题: 删除文件进垃圾箱
发信站: 哈工大紫丁香 (Thu Jun 24 14:35:09 1999), 转信
发信站: 饮水思源站 (Thu Jun 10 15:54:20 1999) , 站内信件
使用以下方法能使删除后的文件进入到回收筒里,而不是被清除。
声明:
Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Public Const FO_DELETE = &H3
Public Const FOF_ALLOWUNDO = &H40
Declare Function SHFileOperation Lib "shell32.dll" Alias _"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
'以上部分可以从API VIEWER中得到。
Public Function ShellDelete(ParamArray vntFileName() As Variant)
Dim I As Integer
Dim sFileNames As String
Dim SHFileOp As SHFILEOPSTRUCT
For I = LBound(vntFileName) To UBound(vntFileName)
sFileNames = sFileNames & vntFileName(I) & vbNullChar
Next I
sFileNames = sFileNames & vbNullChar
With SHFileOp
.wFunc = FO_DELETE
.pFrom = sFileNames
.fFlags = FOF_ALLOWUNDO
End With
ShellDelete = SHFileOperation(SHFileOp)
End Function
'程序中加入CommonDialog,CommandButton:
Private Sub Command1_Click()
Dim FileToKill As String
commondialog1.showopen
FileToKill = commondialog.filename
if filetokill<>"" then
ShellDelete FileToKill
MsgBox "File(s) deleted"
endif
End Sub
--
※ 来源:·饮水思源站 bbs.sjtu.edu.cn·[FROM: 202.120.18.28]
--
☆ 来源:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: Friendsp.bbs@bbs.sjt]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.168毫秒