當前位置:首頁 » 文件管理 » 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 瀏覽:576
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:867
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:565
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:747
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:667
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:988
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:236
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:96
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:789
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:695