解壓密碼:1299
目前成都創(chuàng)新互聯(lián)公司已為數(shù)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站托管運(yùn)營、企業(yè)網(wǎng)站設(shè)計(jì)、遂川網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
假設(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 SubEnd Class
詳見源代碼??!
IO.Directory.GetDirectories("文件夾") '獲取文件夾中的所有子文件夾路徑。
IO.Directory.GetFiles("文件夾") '獲取文件夾下所有文件的路徑。
'子文件夾的子文件夾,用遞歸;
Private Sub GetChilren(ByVal Subject As String)
For Each i As String In My.Computer.FileSystem.GetDirectories(Subject)
GetChilren(i)'在這里遞歸
Next
For Each i As String In My.Computer.FileSystem.GetFiles(Subject)
'''txt,用全局變量或參數(shù)類數(shù)組、泛型、控件保存每個(gè)i
Next
End Sub
給你一個(gè)提示吧!呵呵,剩下的要自己思考哦!
Path:是初始目錄的路徑
Private Sub WriteArray(ByVal Path As String)
'寫入數(shù)組代碼在這里,直接將Path寫到數(shù)組就行了。
Dim dir As New IO.DirectoryInfo(Path)
For Each d As IO.DirectoryInfo In dir.GetDirectories
WriteArray(d.FullName) '遞歸
Next
End Sub
如果子目錄較多那么遞歸會比較費(fèi)時(shí)間,在調(diào)用遞歸前加入application.doevent就行了,這樣在應(yīng)對大遞歸時(shí)不會死機(jī)。
至于數(shù)組嘛使用 arraylist 最好了。
回答補(bǔ)充:
把遞歸去掉就行了啊!
vb.net:
Dim path = System.IO.Directory.GetFiles("D:\Log\abc", "*.txt", SearchOption.AllDirectories):搜索該路徑下的所有txt類型的目錄及子目錄
path.AddRange(path)
Dim _RecordInfo As String
Dim _Reader As StreamReader
_Reader = New StreamReader(file, System.Text.Encoding.Default):'以Default編碼的形式讀取file文件(文件寫入的編碼要與讀取的編碼一致)