3个回答
展开全部
Vb删除文件到回收站代码文件:
view sourceprint?
01
VERSION 5.00
02
Begin VB.Form Form1
03
Caption = "将文件删除到回收站"
04
ClientHeight = 3585
05
ClientLeft = 60
06
ClientTop = 345
07
ClientWidth = 5445
08
LinkTopic = "Form1"
09
ScaleHeight = 3585
10
ScaleWidth = 5445
11
StartUpPosition = 3 '窗口缺省
12
Begin VB.CommandButton Command1
13
Caption = "删除到回收站"
14
Height = 450
15
Left = 3885
16
TabIndex = 4
17
Top = 3060
18
Width = 1365
19
End
20
Begin VB.Frame Frame1
21
Height = 3015
22
Left = 0
23
TabIndex = 0
24
Top = 0
25
Width = 5430
26
Begin VB.FileListBox File1
27
Height = 2610
28
Left = 2595
29
TabIndex = 3
30
Top = 240
31
Width = 2715
32
End
33
Begin VB.DirListBox Dir1
34
Height = 2190
35
Left = 60
36
TabIndex = 2
37
Top = 660
38
Width = 2475
39
End
40
Begin VB.DriveListBox Drive1
41
Height = 300
42
Left = 90
43
TabIndex = 1
44
Top = 255
45
Width = 2490
46
End
47
End
48
End
49
Attribute VB_Name = "Form1"
50
Attribute VB_GlobalNameSpace = False
51
Attribute VB_Creatable = False
52
Attribute VB_PredeclaredId = True
53
Attribute VB_Exposed = False
54
Option Explicit
55
Private Declare Function SHFileOperation Lib _
56
"shell32.dll" Alias "SHFileOperationA" (lpFileOp _
57
As SHFILEOPSTRUCT) As Long '删除到回收站
58
Private Const FO_DELETE = &H3
59
Private Const FOF_ALLOWUNDO = &H40
60
Private Type SHFILEOPSTRUCT
61
hwnd As Long
62
wFunc As Long
63
pFrom As String
64
pTo As String
65
fFlags As Integer
66
fAnyOperationsAborted As Long
67
hNameMappings As Long
68
lpszProgressTitle As Long
69
End Type
70
Private Sub Command1_Click()
71
Dim SHop As SHFILEOPSTRUCT
72
Dim strfile As String
73
If File1.FileName <> "" Then
74
strfile = IIf(Right(File1.Path, 1) = "\", File1.Path, File1.Path & "\")
75
strfile = strfile & File1.FileName
76
Else
77
strfile = Dir1.List(Dir1.ListIndex)
78
End If
79
With SHop
80
.wFunc = FO_DELETE
81
.pFrom = strfile
82
.fFlags = FOF_ALLOWUNDO
83
End With
84
SHFileOperation SHop
85
File1.Refresh
86
Dir1.Refresh
87
End Sub
88
Private Sub Dir1_Change()
89
File1.Path = Dir1.Path
90
End Sub
91
Private Sub Drive1_Change()
92
Dir1.Path = Drive1.Drive
93
End Sub
view sourceprint?
01
VERSION 5.00
02
Begin VB.Form Form1
03
Caption = "将文件删除到回收站"
04
ClientHeight = 3585
05
ClientLeft = 60
06
ClientTop = 345
07
ClientWidth = 5445
08
LinkTopic = "Form1"
09
ScaleHeight = 3585
10
ScaleWidth = 5445
11
StartUpPosition = 3 '窗口缺省
12
Begin VB.CommandButton Command1
13
Caption = "删除到回收站"
14
Height = 450
15
Left = 3885
16
TabIndex = 4
17
Top = 3060
18
Width = 1365
19
End
20
Begin VB.Frame Frame1
21
Height = 3015
22
Left = 0
23
TabIndex = 0
24
Top = 0
25
Width = 5430
26
Begin VB.FileListBox File1
27
Height = 2610
28
Left = 2595
29
TabIndex = 3
30
Top = 240
31
Width = 2715
32
End
33
Begin VB.DirListBox Dir1
34
Height = 2190
35
Left = 60
36
TabIndex = 2
37
Top = 660
38
Width = 2475
39
End
40
Begin VB.DriveListBox Drive1
41
Height = 300
42
Left = 90
43
TabIndex = 1
44
Top = 255
45
Width = 2490
46
End
47
End
48
End
49
Attribute VB_Name = "Form1"
50
Attribute VB_GlobalNameSpace = False
51
Attribute VB_Creatable = False
52
Attribute VB_PredeclaredId = True
53
Attribute VB_Exposed = False
54
Option Explicit
55
Private Declare Function SHFileOperation Lib _
56
"shell32.dll" Alias "SHFileOperationA" (lpFileOp _
57
As SHFILEOPSTRUCT) As Long '删除到回收站
58
Private Const FO_DELETE = &H3
59
Private Const FOF_ALLOWUNDO = &H40
60
Private Type SHFILEOPSTRUCT
61
hwnd As Long
62
wFunc As Long
63
pFrom As String
64
pTo As String
65
fFlags As Integer
66
fAnyOperationsAborted As Long
67
hNameMappings As Long
68
lpszProgressTitle As Long
69
End Type
70
Private Sub Command1_Click()
71
Dim SHop As SHFILEOPSTRUCT
72
Dim strfile As String
73
If File1.FileName <> "" Then
74
strfile = IIf(Right(File1.Path, 1) = "\", File1.Path, File1.Path & "\")
75
strfile = strfile & File1.FileName
76
Else
77
strfile = Dir1.List(Dir1.ListIndex)
78
End If
79
With SHop
80
.wFunc = FO_DELETE
81
.pFrom = strfile
82
.fFlags = FOF_ALLOWUNDO
83
End With
84
SHFileOperation SHop
85
File1.Refresh
86
Dir1.Refresh
87
End Sub
88
Private Sub Dir1_Change()
89
File1.Path = Dir1.Path
90
End Sub
91
Private Sub Drive1_Change()
92
Dir1.Path = Drive1.Drive
93
End Sub
展开全部
先用File来判断该文件是否存在:fileexits(),然后delete就可以了,相关语句及用法,可以查看windows api中的文件操作部分!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim strfile as string
dim filepath as string ''为监控的文件全路径
strfile = dir(filepath,vbnormal)
if strfile <> "" then kill filepath
dim filepath as string ''为监控的文件全路径
strfile = dir(filepath,vbnormal)
if strfile <> "" then kill filepath
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |