当前位置:首页 » 文件管理 » vb扫描文件夹文件

vb扫描文件夹文件

发布时间: 2023-03-06 17:28:02

⑴ 用VB怎么监控文件夹是否有新的文件生成

我自创的方法。考虑到实时检测是否有新文件,应该用一个Timer。

画两个FileListBox控件,控件名分别为File1、File2;画一个TextBox,名为Text1;画一个Timer,名为Timer1。要求将目标文件夹新生成的Txt文件内容显示到Text1中。

Private Sub Form_Load()
File1.Path = "在引号里打上要监测的路径。如果路径不是某个盘的根目录则不要在最后一个文件夹名的后面打上“\”"
File2.Path = File1.Path
File1.Pattern = "*.txt"
File2.Pattern = "*.txt"
File1.Visible = False
File2.Visible = False
Timer1.Interval = 在等号后面打上一个整数用来确定扫描新文件的频率,单位是毫秒,最低值是1
End Sub

Private Sub Timer1_Timer()
File2.Refresh
If File2.ListCount > File1.ListCount Then
If File1.ListCount = 0 Then
File2.ListIndex = 0
Else
i = 0
File1.ListIndex = i
File2.ListIndex = i
Do While File2.FileName = File1.FileName And i <= File1.ListCount - 1
File1.ListIndex = i
File2.ListIndex = i
i = i + 1
Loop
If i = File1.ListCount - 1 Then
File2.ListIndex = i - 1
Else
File2.ListIndex = i
End If
End If
url = File2.Path
If Right(url, 1) <> "\" Then
url = url & "\"
End If
url = url & File2.FileName
Open url For Input As #1
Text1.Text = StrConv(InputB(LOF(1), #1), vbUnicode)
Close #1
File1.Refresh
End If
If File2.ListCount < File1.ListCount Then
File1.Refresh
End If
End Sub

绝对好使,我在VB上试过了。

热点内容
内置存储卡可以拆吗 发布:2025-05-18 04:16:35 浏览:336
编译原理课时设置 发布:2025-05-18 04:13:28 浏览:378
linux中进入ip地址服务器 发布:2025-05-18 04:11:21 浏览:612
java用什么软件写 发布:2025-05-18 03:56:19 浏览:32
linux配置vim编译c 发布:2025-05-18 03:55:07 浏览:107
砸百鬼脚本 发布:2025-05-18 03:53:34 浏览:944
安卓手机如何拍视频和苹果一样 发布:2025-05-18 03:40:47 浏览:742
为什么安卓手机连不上苹果7热点 发布:2025-05-18 03:40:13 浏览:803
网卡访问 发布:2025-05-18 03:35:04 浏览:511
接收和发送服务器地址 发布:2025-05-18 03:33:48 浏览:372