當前位置:首頁 » 文件管理 » 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-09-18 13:51:33 瀏覽:816
php從入門到精通下載 發布:2025-09-18 13:36:44 瀏覽:143
抖音使用腳本 發布:2025-09-18 13:29:36 瀏覽:792
c語言是王道 發布:2025-09-18 13:17:07 瀏覽:265
c語言des 發布:2025-09-18 13:10:39 瀏覽:661
編譯地址超出范圍 發布:2025-09-18 13:01:34 瀏覽:739
怎麼下載php 發布:2025-09-18 12:41:53 瀏覽:222
php登錄原理 發布:2025-09-18 12:37:00 瀏覽:606
php全等 發布:2025-09-18 12:36:55 瀏覽:644
c語言怎麼表示奇數 發布:2025-09-18 12:26:21 瀏覽:419