方法很多,下面列舉一個(gè):
十多年的加查網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。網(wǎng)絡(luò)營(yíng)銷(xiāo)推廣的優(yōu)勢(shì)是能夠根據(jù)用戶(hù)設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整加查建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)公司從事“加查網(wǎng)站設(shè)計(jì)”,“加查網(wǎng)站推廣”以來(lái),每個(gè)客戶(hù)項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
窗體上添加2個(gè)列表框,一個(gè)按鈕:
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
給你一個(gè)提示吧!呵呵,剩下的要自己思考哦!
Path:是初始目錄的路徑
Private Sub WriteArray(ByVal Path As String)
'寫(xiě)入數(shù)組代碼在這里,直接將Path寫(xiě)到數(shù)組就行了。
Dim dir As New IO.DirectoryInfo(Path)
For Each d As IO.DirectoryInfo In dir.GetDirectories
WriteArray(d.FullName) '遞歸
Next
End Sub
如果子目錄較多那么遞歸會(huì)比較費(fèi)時(shí)間,在調(diào)用遞歸前加入application.doevent就行了,這樣在應(yīng)對(duì)大遞歸時(shí)不會(huì)死機(jī)。
至于數(shù)組嘛使用 arraylist 最好了。
回答補(bǔ)充:
把遞歸去掉就行了啊!
解壓密碼:1299
假設(shè)路徑為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
詳見(jiàn)源代碼??!
vb.net:
Dim
path
=
System.IO.Directory.GetFiles("D:\Log\abc",
"*.txt",
SearchOption.AllDirectories):搜索該路徑下的所有txt類(lèi)型的目錄及子目錄
path.AddRange(path)
Dim
_RecordInfo
As
String
Dim
_Reader
As
StreamReader
_Reader
=
New
StreamReader(file,
System.Text.Encoding.Default):'以Default編碼的形式讀取file文件(文件寫(xiě)入的編碼要與讀取的編碼一致)
'把下面的目錄改成你要遍歷的目錄
Dim MyDir = "C:\Windows"
Dim MyInfo = MyDir + "目錄下的所有文件包括:"
For Each MyFile In System.IO.Directory.GetFiles(MyDir)
MyInfo += Environment.NewLine + MyFile
Next
Me.RichTextBox1.Text =MyInfo