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

vb如何实现监控某个文件如果存在就删除它?谢谢!... vb如何实现 监控某个文件 如果存在就删除它? 谢谢! 展开
 我来答
小林子LWL
2015-10-23 · 知道合伙人餐饮行家
小林子LWL
知道合伙人餐饮行家
采纳数:57 获赞数:16160
河南科技大学在校本科生

向TA提问 私信TA
展开全部
  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
俊秀还开心的小饼干J
2010-12-01
知道答主
回答量:20
采纳率:0%
帮助的人:14.3万
展开全部
先用File来判断该文件是否存在:fileexits(),然后delete就可以了,相关语句及用法,可以查看windows api中的文件操作部分!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
danver1207
推荐于2016-08-20 · TA获得超过127个赞
知道小有建树答主
回答量:324
采纳率:0%
帮助的人:241万
展开全部
dim strfile as string
dim filepath as string ''为监控的文件全路径
strfile = dir(filepath,vbnormal)
if strfile <> "" then kill filepath
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式