当前位置:首页 » 文件管理 » 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-07-05 16:10:30 浏览:517
微博数据库设计 发布:2025-07-05 15:30:55 浏览:20
linux485 发布:2025-07-05 14:38:28 浏览:299
php用的软件 发布:2025-07-05 14:06:22 浏览:751
没有权限访问计算机 发布:2025-07-05 13:29:11 浏览:428
javaweb开发教程视频教程 发布:2025-07-05 13:24:41 浏览:689
康师傅控流脚本破解 发布:2025-07-05 13:17:27 浏览:235
java的开发流程 发布:2025-07-05 12:45:11 浏览:681
怎么看内存卡配置 发布:2025-07-05 12:29:19 浏览:279
访问学者英文个人简历 发布:2025-07-05 12:29:17 浏览:828