类型的未经处理的异常在 mscorlib.dll 中发生 索引超出范围。必须为非负值并小于集合大小。
发生的代码片段:
For Each filepath In ListView1.Items
Dim folderArr = My.Computer.FileSystem.GetDirectoryInfo(filepath.Text)
'先获取主目录文件
For Each foundFile In My.Computer.FileSystem.GetFiles(folderArr.FullName, FileIO.SearchOption.SearchTopLevelOnly, mySearchPattern)
ListBox1.Items.Add(foundFile)
Next
'再获取子目录文件
For Each folder In folderArr.GetDirectories()
' ToolStripStatusLabel4.Text = folder.ToString
'Try
For Each foundFile In My.Computer.FileSystem.GetFiles(folder.FullName, FileIO.SearchOption.SearchAllSubDirectories, mySearchPattern)
'ToolStripStatusLabel4.Text = "正在扫描:" & foundFile '!!!这里不能给toolStripstatuslabel4设置,不然会弹出索引超出范围
'获取文件大小
If My.Computer.FileSystem.GetFileInfo(foundFile).Length >= minFileSize * 1024 * 1024 And My.Computer.FileSystem.GetFileInfo(foundFile).Length <= maxFileSize * 1024 * 1024 Then
ListBox1.Items.Add(foundFile)
End If
Next
Next
Next
原因在于不能给toolStripstatuslabel4设置,不然会弹出索引超出范围