当前位置:首页 » 文件管理 » vb检查文件是否可以删除
扩展阅读
文件管理栏可以不用吗 2025-05-18 01:04:04
电脑数据怎样按日期备份 2025-05-18 01:03:20

vb检查文件是否可以删除

发布时间: 2023-01-07 16:35:05

① VB 如何实现:检测文件夹是否存在某个文件,有的话删除文件夹以及文件

if dir(App.path&"\"&FileName)<>"" then
kill App.path&"\"&FileName
end if

这样就可以了 dir函数用法请网络

② VB 提示是否删除

_click() dim a% a=msgbox("是否删除",vbOKCancel, "删除确定") If a = 0 Then exit sub

③ vb6.0如何编写查找某文件夹中指定文件是否存在并删除该指定文件的代码,多谢大师

if Dir("c:\abc.txt", vbNormal)="abc.txt" then
msgbox "文件存在"
kill "c:\abc.txt"
else
msgbox "文件不存在"
end if

④ 怎么样用VB删除文件

先用
Dir
函数
检测文件是否存在再用
Kill语句
删除文件即可。

⑤ vb如果存在该文件就删除它

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