當前位置:首頁 » 文件管理 » vb檢查文件是否可以刪除
擴展閱讀
u盤插在手機上怎樣投屏 2025-05-17 21:34:57

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