当前位置:首页 » 文件管理 » 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上试过了。

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:710
制作脚本网站 发布:2025-10-20 08:17:34 浏览:972
python中的init方法 发布:2025-10-20 08:17:33 浏览:681
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:833
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:741
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1081
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:312
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:192
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:880
python股票数据获取 发布:2025-10-20 07:39:44 浏览:837