怎样将文件放到回收站?

ksy 2003-03-18 08:36:12
我直接把文件移动到回收站,行不行?
...全文
60 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dugu_Niu 2003-03-18
  • 打赏
  • 举报
回复
看看下面这个文章,会对你有所帮助

Exploit the FileSystemObject Class.

http://www.fawcette.com/vsm/2002_08/magazine/columns/gettingstarted/default_pf.asp
Dugu_Niu 2003-03-18
  • 打赏
  • 举报
回复
Want to delete a file and have it go into the recycle bin? The Kill statement
permanently deletes the file. Instead, try the following:

Private Declare Function SHFileOperation Lib _
"shell32.dll" (ByRef lpFileOp As _
SHFILEOPSTRUCT) As Long

Private Const ERROR_SUCCESS = 0&
Private Const FO_COPY = &H2
Private Const FO_DELETE = &H3
Private Const FO_MOVE = &H1
Private Const FO_RENAME = &H4
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_CONFIRMMOUSE = &H2
Private Const FOF_FILESONLY = &H80
Private Const FOF_MULTIDESTFILES = &H1
Private Const FOF_NOCONFIRMATION = &H10
Private Const FOF_NOCONFIRMMKDIR = &H200
Private Const FOF_RENAMEONCOLLISION = &H8
Private Const FOF_SILENT = &H4
Private Const FOF_SIMPLEPROGRESS = &H100
Private Const FOF_WANTMAPPINGHANDLE = &H20

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 ' only used if FOF_SIMPLEPROGRESS
End Type

Next create a function called Recycle, like so

Public Sub Recycle(ByVal FileName As String)
Dim CFileStruct As SHFILEOPSTRUCT

With CFileStruct
.hwnd = Me.hwnd
.fFlags = FOF_ALLOWUNDO
.pFrom = FileName
.wFunc = FO_DELETE
End With

If SHFileOperation(CFileStruct) <> ERROR_SUCCESS Then
'An error occurred.
End If

End Sub

To test the procedure, create a dummy text file, drop a command button onto a
Visual Basic form, and then attach the following code

Private Sub Command1_Click()
Recycle "c: est.txt"
End Sub

When you click the button, Windows asks if you want to move the file to the Recycle Bin.
Dugu_Niu 2003-03-18
  • 打赏
  • 举报
回复
好像只能使用api吧。

16,552

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧