vb.net:
天臺ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
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文件(文件寫入的編碼要與讀取的編碼一致)
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ù)組、泛型、控件保存每個i
Next
End Sub
'把下面的目錄改成你要遍歷的目錄
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
給你一個提示吧!呵呵,剩下的要自己思考哦!
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
如果子目錄較多那么遞歸會比較費時間,在調(diào)用遞歸前加入application.doevent就行了,這樣在應對大遞歸時不會死機。
至于數(shù)組嘛使用 arraylist 最好了。
回答補充:
把遞歸去掉就行了啊!
IO.Directory.GetDirectories("文件夾") '獲取文件夾中的所有子文件夾路徑。
IO.Directory.GetFiles("文件夾") '獲取文件夾下所有文件的路徑。
'子文件夾的子文件夾,用遞歸;
解壓密碼:1299
假設路徑為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
詳見源代碼?。?/p>
當前題目:vbnet遍歷文件 vbnet操作數(shù)據(jù)庫
本文URL:http://weahome.cn/article/hiegih.html