解壓密碼:1299
專注于為中小企業(yè)提供網(wǎng)站設計制作、成都做網(wǎng)站服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)清豐免費做網(wǎng)站提供優(yōu)質(zhì)的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
假設路徑為C:\abc
代碼:
Public?Class?Form1
Private?Sub?Form1_Load(sender?As?Object,?e?As?EventArgs)?Handles?MyBase.Load
Dim?Files?As?ObjectModel.ReadOnlyCollection(Of?String)?=?My.Computer.FileSystem.GetFiles("C:\abc")
Dim?FileSize?As?Long,?FileName?As?String?=?Nothing
Dim?oFileSize?As?Long
For?Each?File?As?String?In?Files
oFileSize?=?My.Computer.FileSystem.GetFileInfo(File).Length
If?oFileSize??FileSize?Then
FileSize?=?oFileSize
FileName?=?File
End?If
Next
Dim?ListN?As?ListViewItem?=?New?ListViewItem(My.Computer.FileSystem.GetName(FileName))
ListN.SubItems.Add(oFileSize??"?byte")
ListN.SubItems.Add(My.Computer.FileSystem.GetFileInfo(FileName).Extension??"?文件")
ListN.SubItems.Add(FileName)
ListView1.Items.Add(ListN)
End?Sub
End?Class
詳見源代碼??!
思路:
1,使用ListBox1控件來存放搜索到的文件名,然后ListBox1.SelectedItem就可以返回選中項的文本;
2,利用獲得的選中項文本(即文件與路徑),使用打開文本文件的方法,讀取內(nèi)容顯示在文本框里。
窗體上添加一個文本框,一個列表框,一個按鈕:
代碼如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyDir As String = "C:\123"
Dim MyFilter As String = "*" TextBox1.Text "*"
ListBox1.Items.Clear()
For Each MyFile As String In System.IO.Directory.GetFiles(MyDir, MyFilter)
ListBox1.Items.Add(MyFile)
Next
End Sub
步驟如下:
窗體上添加2個列表框,一個按鈕:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyDir As String = "C:\123"
'搜索并顯示子文件夾
ListBox1.Items.Clear()
For Each MySubDir As String In System.IO.Directory.GetDirectories(MyDir)
ListBox1.Items.Add(MySubDir)
Next
'搜索并顯示文件
ListBox2.Items.Clear()
For Each MyFile As String In System.IO.Directory.GetFiles(MyDir)
ListBox2.Items.Add(MyFile)
Next
End Sub
End Class