你实例化一个文件对象,就可以获取这个文件的相关属性了,VB.NET实例,以你的文件为例:
创新互联于2013年成立,是专业互联网技术服务公司,拥有项目网站建设、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元边坝做网站,已为上家服务,为边坝各地企业和个人服务,联系电话:18980820575
Dim sourcefileinfo As New FileInfo(“ c:\1.txt”) '定义并实例化FileInfo对象。length就是它的大小!
label1.Text = "文件大小为: " sourcefileinfo.Length "字节"
CSV文件特征是每行一条记录,字段用逗号分开。你只需要逐行处理,将每行文本用逗号切分得到数组array,然后判断array[0]是否等于"bbb",如果相等则array[1]就是”4561234567890“;如果不等则继续处理下一行。
窗体上添加一个按钮,代码如下:
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() + "字节。"
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