窗體上添加一個(gè)按鈕,代碼如下:
成都創(chuàng)新互聯(lián)長(zhǎng)期為上1000+客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為興隆企業(yè)提供專業(yè)的網(wǎng)站制作、成都做網(wǎng)站,興隆網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Text = "稍等!"
Button1.Enabled = False
Dim MyFolder As String = "C:\Windows"
Dim MyDir As New System.IO.DirectoryInfo(MyFolder)
Dim MyInfo As String = MyFolder + "文件夾的大小是:" + CalculateDirectorySize(MyDir, True).ToString() + "字節(jié)。"
MessageBox.Show(MyInfo, "信息提示", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Button1.Text = "開始"
Button1.Enabled = True
End Sub
Public Shared Function CalculateDirectorySize(ByVal MyDirectory As System.IO.DirectoryInfo, ByVal IsSubDirectories As Boolean) As Long
Dim MySize As Long = 0
'檢查包含的所有文件
Dim MyFiles() As System.IO.FileInfo = MyDirectory.GetFiles()
For Each MyFile As System.IO.FileInfo In MyFiles
MySize += MyFile.Length
Next
'檢查包含的所有子文件夾
If (IsSubDirectories) Then
Dim MyDirs() As System.IO.DirectoryInfo = MyDirectory.GetDirectories()
For Each MyDir As System.IO.DirectoryInfo In MyDirs
MySize += CalculateDirectorySize(MyDir, True)
Next
End If
Return MySize
End Function
End Class
CSV文件特征是每行一條記錄,字段用逗號(hào)分開。你只需要逐行處理,將每行文本用逗號(hào)切分得到數(shù)組array,然后判斷array[0]是否等于"bbb",如果相等則array[1]就是”4561234567890“;如果不等則繼續(xù)處理下一行。
你實(shí)例化一個(gè)文件對(duì)象,就可以獲取這個(gè)文件的相關(guān)屬性了,VB.NET實(shí)例,以你的文件為例:
Dim sourcefileinfo As New FileInfo(“ c:\1.txt”) '定義并實(shí)例化FileInfo對(duì)象。length就是它的大??!
label1.Text = "文件大小為: " sourcefileinfo.Length "字節(jié)"