VB.NET遍历查找某个文件夹,并找出指定文件
VB.NET遍历查找目录下的ABC文件夹,并找出此ABC文件夹中文件体积最大的一个文件列出到ListView1,ListView1的列分别是“文件名”、“文件大小”、“文...
VB.NET遍历查找目录下的ABC文件夹,并找出此ABC文件夹中文件体积最大的一个文件列出到ListView1,
ListView1的列分别是“文件名”、“文件大小”、“文件格式”、“文件路径”
希望越详细越好,谢谢! 展开
ListView1的列分别是“文件名”、“文件大小”、“文件格式”、“文件路径”
希望越详细越好,谢谢! 展开
1个回答
展开全部
解压密码: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 Sub
End Class
详见源代码!!
更多追问追答
追答
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
If FileName <> Nothing Then '修改的地方
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 If
End Sub
End Class
请问还会出现错误吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |